jsp

位置:IT落伍者 >> jsp >> 浏览文章

jsp自动生成静态文件(html)


发布日期:2021年08月28日
 
jsp自动生成静态文件(html)

htmljsp

<%@ page contentType="text/html;charset=utf"%>
<%@page import="cnnbaianewPagenewsPage*cnnbaianewPagenewsImg*javautil*cnnbaianewPagecolumnPage*cnnbaiacompany*cnnbaialink*" %>
<%@page import="javaio*" %>
<%

//在这里如果写成“WEBINF/templates/templatehtm”程序会报错
String filePath = requestgetRealPath("/")+"test/templatehtm";
outprint(filePath);
String templateContent="";

FileInputStream fileinputstream = new FileInputStream(filePath);//读取模块文件
int lenght = fileinputstreamavailable();
byte bytes[] = new byte[lenght ];
fileinputstreamread(bytes);
fileinputstreamclose();

templateContent = new String(bytes);
int newsid=;//requestgetParameter("id");
newsCtl nCtl=new newsCtl();
news news=new news();
// newsImg newsimg=new newsImg();
//newsImgCtl nImgCtl=new newsImgCtl();
news=nCtlselectOneById(newsid);
//int rector=newsgetRedactor();
//String source=newsgetSource();
//String datetime=newsgetDateTime();
//int degree=newsgetBrowseDegree();
//int companyid=newsgetCompanyId();
String title=newsgetTitle();
String content=newsgetContent();
if(title==null) title="";
//if(source==null) source="";
//if(datetime==null) datetime="";
if(content==null) content="";
templateContent=templateContentreplaceAll("#title#"title);
templateContent=templateContentreplaceAll("#content#"content);
// 根据时间得文件名
Calendar calendar = CalendargetInstance();
String fileame = StringvalueOf(newsid) +"html";
String file = "filename/"+StringvalueOf(newsid) +"html";
fileame = requestgetRealPath("/")+"/filename/"+fileame;//生成的html文件保存路径
outprint(templateContent);
FileOutputStream fileoutputstream = new FileOutputStream(fileame);//建立文件输出流
byte tag_bytes[] = templateContentgetBytes("utf");
//String username = "";
//username = new String(usernamegetBytes("ISO_")"GB");
fileoutputstreamwrite(tag_bytes);
fileoutputstreamclose();
responsesendRedirect("/"+file);
//outprint("<script>windowlocation/"+file+";</script>");
%>


模版页面

templatehtm

<%@ page contentType="text/html;charset=utf"%>
<html>
<head>
<title>jsp</title>

<meta httpequiv="keywords" content="keywordkeywordkeyword">
<meta httpequiv="description" content="this is my page">
<meta httpequiv="contenttype" content="text/html; charset=UTF">

<!<link rel="stylesheet" type="text/css" href="/stylescss">>

</head>

<body><!top start><SPAN id=showTop></SPAN><IE:DOWNLOAD
id=oDownload style="BEHAVIOR: url(#default#download)" />
<SCRIPT>
function topOnDownloadDone(downDate){
showTopinnerHTML=downDate
}
oDownloadstartDownload(inc/topjsptopOnDownloadDone)
</SCRIPT>
<!top end>
<TABLE width="" border="" align="center" cellpadding="" cellspacing="">
<tr><td valign="top" bgcolor="#FFFFFF"><div align="center" class="dp">#title#</div></td></tr>
<tr><td valign="top" bgcolor="#FFFFFF"><div align="center" class="dp">#content#</div></td></tr>
</TABLE>
<!bottom start><SPAN id=showBottom></SPAN>
<SCRIPT>
function bottomOnDownloadDone(downDate)
{
showBottominnerHTML=downDate
}
oDownloadstartDownload(inc/bottomjspbottomOnDownloadDone)
</SCRIPT><!bottom end></body></html>

               

上一篇:怎么在JSP中跳转到别一页面

下一篇:JSP中”预定义变量”的使用