jsp自動產生靜態檔案(html)

來源:互聯網
上載者: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.*" %>
<%

//在這裡如果寫成“WEB-INF/templates/template.htm”程式會報錯
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);
// 根據時間得檔案名稱
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>

來源:csdn
 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.