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