JSP automatically generates static files (HTML)

Source: Internet
Author: User
Tags datetime

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 you write "web-inf/templates/template.htm", you'll get an error.
String FilePath = Request.getrealpath ("/") + "test/template.htm";
Out.print (FilePath);
String templatecontent= "";

FileInputStream FileInputStream = new FileInputStream (filePath);//Read 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 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);
//File name based on time
Calendar calendar = calendar.getinstance ();
String fileame = string.valueof (NewSID) + ". html";
String file = "filename/" +string.valueof (NewSID) + ". html";
Fileame= Request.getrealpath ("/") + "/filename/" +fileame;//the generated HTML file save path
Out.print (TemplateContent);
FileOutputStream FileOutputStream = new FileOutputStream (fileame);//create 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> ");
%>


Stencil page:

Template.htm

<%@ page contenttype= "Text/html;charset=utf-8"%>
<title>jsp</title>

<meta http-equiv= "keywords" content= "keyword1,keyword2,keyword3" >
<meta http-equiv= "description" content= "This are my page" >
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">

<!--<link rel= "stylesheet" type= "Text/css" href= "./styles.css" >-->

<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.jsp ', topondownloaddone)
</SCRIPT>
<!--top End-->
<table width= "778" border= "0" align= "center" cellpadding= "0" cellspacing= "0"
& LT;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.jsp ', bottomondownloaddone)
</script><!--bottom End--></body>

Source: csdn
 

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.