国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JSP > 正文

jsp自動(dòng)生成靜態(tài)文件(html)

2024-09-05 00:17:26
字體:
供稿:網(wǎng)友

jsp自動(dòng)生成靜態(tài)文件(html):

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.*" %>
<%

//在這里如果寫成“WEB-INF/templates/template.htm”程序會(huì)報(bào)錯(cuò)
String filePath = request.getRealPath("/")+"test/template.htm";
out.print(filePath);
String templateContent="";

FileInputStream fileinputstream = new FileInputStream(filePath);//讀取模塊文件
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);
// 根據(jù)時(shí)間得文件名
Calendar calendar = Calendar.getInstance();
String fileame = String.valueOf(newsid) +".html";
String file = "filename/"+String.valueOf(newsid) +".html";
fileame = request.getRealPath("/")+"/filename/"+fileame;//生成的html文件保存路徑
out.print(templateContent);
FileOutputStream fileoutputstream = new FileOutputStream(fileame);//建立文件輸出流
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.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.jsp',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.jsp',bottomOnDownloadDone)
</SCRIPT><!--bottom end--></body></html>
 

 

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 武威市| 镇平县| 锡林郭勒盟| 额济纳旗| 晋中市| 军事| 苍山县| 屏东市| 库伦旗| 丹寨县| 嫩江县| 丹东市| 习水县| 澄江县| 巧家县| 胶州市| 成安县| 松阳县| 兴国县| 宁德市| 嘉黎县| 徐闻县| 怀远县| 济阳县| 太仆寺旗| 丰台区| 雷州市| 彝良县| 平利县| 金门县| 洛隆县| 上林县| 壶关县| 平果县| 海口市| 太谷县| 黄大仙区| 额尔古纳市| 高陵县| 慈溪市| 仲巴县|