js| News | static | Web page
The following code is the use of JSP to generate static HTML
<%@ page contenttype= "TEXT/HTML;CHARSET=GBK"%>
<% @page import= "java.util.*"%>
<% @page import= "java.io.*"%>
<%
Here, if you write "web-inf\templates\template.htm", you'll get an error.
String FilePath = Request.getrealpath ("/") + "web-inf/templates/template.htm";
Out.print (FilePath);
String templatecontent= "";
FileInputStream FileInputStream = new FileInputStream (filePath);//Read Module file
int lenght = fileinputstream.available ();
byte bytes[] = new byte[1024];
Fileinputstream.read (bytes);
Fileinputstream.close ();
TemplateContent = new String (bytes);
Out.print ("Below is the template content:<br>" +templatecontent+ "<br> below is the replacement HTML content <br>Templatecontent=templatecontent.replaceall ("#title #", "title of the article");
Templatecontent=templatecontent.replaceall ("#author #", "Who is the author");//replace the corresponding place in the module
Templatecontent=templatecontent.replaceall ("#content #", "article content");
According to the time file name
Calendar calendar = Calendar.getinstance ();
String fileame = string.valueof (Calendar.gettimeinmillis ()) + ". html";
Fileame = Request.getrealpath ("/") +fileame;//the generated HTML file save path
Out.print (TemplateContent);
FileOutputStream FileOutputStream = new FileOutputStream (fileame);//create file output stream
byte tag_bytes[] = Templatecontent.getbytes ();
Fileoutputstream.write (tag_bytes);
Fileoutputstream.close ();
%>