1. Modify the file editor ewebeditor used to add news content
2. Store the file name and title in the database to facilitate the foreground to call these generated static news pages.
1. An error occurred while displaying the image after ewebeditor was added.
Generated is
However, this static news page is in the folder, so
(Note: Here I set this project to the root directory)
Solution:
String article = new string (request. getparameter ("article"). getbytes ("iso-8859-1"), "gb2312 ");
Int Index = article. indexof ("IMG ");
System. Out. Print (Article); //
If (article. indexof ("IMG")> 0)
{
Article = article. replaceall ("/uploadfile", "../uploadfile ");
}
System. Out. Print (Article); //
2. Insert the database (generated HTML, such as 2008-07-16/1216200066859. html, song name, and add time)
Create Table 'smusic '(
'Id' int (11) not null auto_increment,
'Name' varchar (100) default null,
'Filesrc' text,
'Singer _ id' varchar (11) default null,
'Type _ id' varchar (11) default & apos; 1 & apos ;,
'Special _ id' int (11) default & apos; 0 & apos ;,
'Tuian Ian 'int (11) default & apos; 0 & apos ;,
'Redian 'int (11) default & apos; 0 & apos ;,
'News' int (11) default & apos; 0 & apos ;,
'Publictime' datetime default null,
Primary Key ('id ')
) Type = MyISAM;
<% @ Page Language = "Java" contenttype = "text/html; charset = UTF-8" errorpage = "" %>
<% @ Page import = "Java. util. *, java. Io. *, java. Text. *, my. Bean. *" %>
<JSP: Directive. Page import = "com. pp. DB. dboperate"/>
<%
String title = new string (request. getparameter ("title"). getbytes ("iso-8859-1"), "gb2312 ");
String url = new string (request. getparameter ("url"). getbytes ("iso-8859-1"), "gb2312 ");
String lyric = new string (request. getparameter ("Lyric"). getbytes ("iso-8859-1"), "gb2312 ");
Simpledateformat format = new simpledateformat ("yyyy-mm-dd ");
String nowtime = format. Format (new date ());
String fileame = "";
Int A = 0;
Try {
String filepath = "", Path = "";
Filepath = request. getrealpath ("/") + "modle.html ";
Filepath = filepath. replaceall ("////","/");
String templatecontent = "";
// Read the hmtl Template File
Fileinputstream FCM = new fileinputstream (filepath );
Stringbuffer content = new stringbuffer ();
Datainputstream in = new datainputstream (FCM );
Bufferedreader BR = new bufferedreader (New inputstreamreader (in, "UTF-8 "));
String line = NULL;
While (line = Br. Readline ())! = NULL)
Content. append (LINE + "/N ");
BR. Close ();
In. Close ();
FCM. Close ();
// Replace the relevant part of the template
Templatecontent = new string (content );
Templatecontent = templatecontent. replaceall ("### title ###", title );
Templatecontent = templatecontent. replaceall ("### URL ###", URL );
Templatecontent = templatecontent. replaceall ("### addtime ###", nowtime );
Templatecontent = templatecontent. replaceall ("### lyric ###", lyric); // replace the corresponding part of the module
System. Out. println (templatecontent );
Calendar calendar = calendar. getinstance ();
Fileame = string. valueof (calendar. gettimeinmillis () + ". html ";
String wfileame = fileame;
// Create a news page storage directory
Path = request. getrealpath ("/") + nowtime + "/";
File d = new file (PATH); // create a file object that represents the sub directory and obtain a reference
If (! D. exists () {// check whether the sub directory exists
D. mkdir (); // create a sub directory
}
File F = new file (path, fileame );
If (! F. exists () {// check whether file.txt exists
F. createnewfile (); // create a file named file.txt in the current directory.
}
Fileame = request. getrealpath ("/") + nowtime + "/" + fileame; // save path of the generated HTML file
// Write the replaced content to the file
Fileoutputstream Fos = new fileoutputstream (fileame );
Writer output = new outputstreamwriter (FOS, "UTF-8 ");
Output. Write (templatecontent );
Output. Close ();
FOS. Close ();
// I need to write it to the database to facilitate frontend call.
Dboperate DBO = new dboperate ();
Smusic = new smusic ();
Smusic. setname (new string (title. getbytes ("gb2312"), "iso-8859-1 "));
Smusic. setfilesrc (nowtime + "/" + wfileame );
Smusic. setpublictime (nowtime );
DBO. insert_update (smusic, "insert ");
Out. println ("<SCRIPT> window. alert (& apos; static news page generated successfully & apos;); window. location. href = & apos; addmusic. JSP & apos; </SCRIPT> ");
} Catch (exception e ){
System. Out. Print (E. tostring ());
}
%>
3 Examples
<% @ Page Language = "Java" Import = "Java. util. *" contenttype = "text/html; charset = gb2312" %>
<% @ Page import = "com. pp. DB. *" %>
<% @ Page import = "My. Bean. *" %>
<! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en"
Http://www.w3.org/TR/html4/loose.dtd>
<HTML>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = GBK">
<Title> index </title>
</Head>
<Script language = "JavaScript" type = "text/JavaScript">
Function reverseselect ()
{
For (VAR I = 0; I <songlist. elements. length; I ++)
If (songlist. elements [I]. Checked = true)
Songlist. elements [I]. Checked = false;
Else
Songlist. elements [I]. Checked = true;
}
Function allselect ()
{
For (VAR I = 0; I <songlist. elements. length; I ++)
Songlist. elements [I]. Checked = true;
}
</SCRIPT>
<Body>
<H2 align = "center"> <em> <strong> <font color = "# ff0000"> online music playback demonstration </font> </strong> </em> </H2>
<Form name = "songlist" method = "Post" Action = "process. jsp">
<Div id = "layer1" style = "position: absolute; width: 783px; Height: 154px; Z-index: 1; left:-5px; top: 141px;">
<Table width = "780" border = "0" cellspacing = "0" cellpadding = "5">
<%
Dboperate DBO = new dboperate ();
DBO. setlength (10 );
String hql = "from smusic ";
List mylist = DBO. findsqlhibernate (hql, 1 );
Int n = mylist. Size ();
For (INT I = 0; I <mylist. Size (); I ++)
{
Smusic music = (smusic) mylist. Get (I );
%>
<Tr>
<TD width = "714"> <ul> <li> <a href = "<% = music. getfilesrc () %> "> <% = new string (music. getname (). getbytes ("iso-8859-1"), "gb2312") %> </a> </LI> </ul> </TD>
<TD width = "25"> <input type = "checkbox" name = "name <% = I %>" value = "<% = music. GETID () %> "> </TD>
</Tr>
<%
}
%>
</Table>
</Div>
<Input type = "button" name = "all" value = "select all" onclick = "allselect ()">
<Input type = "button" name = "reverse" value = "invert" onclick = "reverseselect ()">
<Input type = "reset" name = "reset" value = "reset">
<Input type = "Submit" name = "Submit" value = "broadcast">
<Input type = "hidden" name = "size" value = "<% = n %>">
</Form>
</Body>
</Html>
Attachment: csdn space/musichouse2 Project