Jsp automatically generates static files (html)

Source: Internet
Author: User

Html. jsp

<% @ Page contentType = "text/html; charset = UTF-8" %>
<% @ Page import = "cn. nbaia. newPage. newsPage. *, cn. nbaia. newPage. newsImg. *, java. util. *, cn. nbaia. newPage. columnPage. *, cn. nbaia. company. *, cn. nbaia. link. * "%>
<% @ Page import = "java. io. *" %>
<%

// Here if the program is written as "WEB-INF/templates/template.htm", an error will be reported
String filePath = request. getRealPath ("/") + "test/template.htm ";
Out. print (filePath );
String templateContent = "";

FileInputStream fileinputstream = new FileInputStream (filePath); // read the module File
Int lenght = fileinputstream. available ();
Byte bytes [] = new byte [lenght];
Fileinputstream. read (bytes );
Fileinputstream. close ();

TemplateContent = new String (bytes );
Int newsid= 2484; // request. getParameter ("id ");
NewsCtl nCtl = new newsCtl ();
News = new news ();
// NewsImg newsimg = new newsImg ();
// NewsImgCtl nImgCtl = new newsImgCtl ();
News = nCtl. selectOneById (newsid );
// Int rector = news. getRedactor ();
// String source = news. getSource ();
// String datetime = news. getDateTime ();
// Int degree = news. getBrowseDegree ();
// Int companyid = news. getCompanyId ();
String title = news. getTitle ();
String content = news. getContent ();
If (title = null) title = "";
// If (source = null) source = "";
// If (datetime = null) datetime = "";
If (content = null) content = "";
TemplateContent = templateContent. replaceAll ("# title #", title );
TemplateContent = templateContent. replaceAll ("# content #", content );
// Get the file name by Time
Calendar calendar = Calendar. getInstance ();
String fileame = String. valueOf (newsid) + ". html ";
String file = "filename/" + String. valueOf (newsid) + ". html ";
Fileame = request. getRealPath ("/") + "/filename/" + fileame; // save path of the generated html file
Out. print (templateContent );
FileOutputStream fileoutputstream = new FileOutputStream (fileame); // create a file output stream
Byte tag_bytes [] = templateContent. getBytes ("UTF-8 ");
// String username = "00 ";
// Username = new String (username. getBytes ("ISO8859_1"), "GB2312 ");
Fileoutputstream. write (tag_bytes );
Fileoutputstream. close ();
Response. sendRedirect ("../" + file );
// Out. print ("<script> window. location. href = '../" + file + "'; </script> ");
%>


Template page:

Template.htm

<% @ Page contentType = "text/html; charset = UTF-8" %>
<Html>
<Head>
<Title> jsp </title>

<Meta http-equiv = "keywords" content = "keyword1, keyword2, keyword3">
<Meta http-equiv = "description" content = "this is my page">
<Meta http-equiv = "content-type" content = "text/html; charset = UTF-8">

<! -- <Link rel = "stylesheet" type = "text/css" href = "./styles.css"> -->

</Head>

<Body> <! -- Top start --> <SPAN id = showTop> </SPAN> <IE: DOWNLOAD
Id = oDownload style = "BEHAVIOR: url (# default # download)"/>
<SCRIPT>
Function topOnDownloadDone (downDate ){
ShowTop. innerHTML = downDate
}
ODownload. startDownload ('inc/top. js', topOnDownloadDone)
</SCRIPT>
<! -- Top end -->
<TABLE width = "778" border = "0" align = "center" cellpadding = "0" cellspacing = "0">
<Tr> <td valign = "top" bgcolor = "# FFFFFF"> <div align = "center" class = "d9p"> # title # </div> </td> </tr>
<Tr> <td valign = "top" bgcolor = "# FFFFFF"> <div align = "center" class = "d9p"> # content # </div> </td> </tr>
</TABLE>
<! -- Bottom start --> <SPAN id = showBottom> </SPAN>
<SCRIPT>
Function bottomOnDownloadDone (downDate)
{
ShowBottom. innerHTML = downDate
}
ODownload. startDownload ('inc/bottom. js', bottomOnDownloadDone)
</SCRIPT> <! -- Bottom end --> </body>

Source: csdn
 

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.