(Unlike generating static html from JSP, all the news is static.
If the HTM template is used, it will be replaced in different places.
)
Similar;
<% @ Page Language = "Java" contenttype = "text/html; charset = UTF-8" errorpage = "" %>
<% @ Page import = "Java. util. *, java. Io. *" %>
<% @ Include file = "../INC/includebean. jsp" %>
<%
Request. setcharacterencoding ("UTF-8 ");
String title = request. getparameter ("newstitle ");
String newsfrom = request. getparameter ("newsfrom ");
String DOCT = request. getparameter ("newsdoct ");
String fileame = "";
Int A = 0;
Try {
String filepath = "", Path = "";
Filepath = request. getrealpath ("/") + "News/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 ("### source ###", newsfrom );
Templatecontent = templatecontent. replaceall ("### addtime ###", nowtime );
Templatecontent = templatecontent. replaceall ("### Article ###", DOCT); // replace the corresponding content in the module
Calendar calendar = calendar. getinstance ();
Fileame = string. valueof (calendar. gettimeinmillis () + ". html ";
// Create a news page storage directory
Path = request. getrealpath ("/") + "News/" + 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 ("/") + "News/" + 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 ();
} Catch (exception e ){
System. Out. Print (E. tostring ());
}
%>
2. The database saves the file title, file name, date, and other information at the same time, and there is no need to retain other information such as news content;
3rd. You can directly retrieve the xxx.htm file name and file title from the data warehouse;