Dynamic Web change static: JSP generates static HTML technology

Source: Internet
Author: User
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 ();
%>



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.