jsp自動(dòng)生成靜態(tài)文件(html)_JSP教程
推薦:用JSP來發(fā)送郵件MESSAGE.JSP TABLE width=555 border=0 align=center cellPadding=0 cellSpacing=0 FORM action=message_do.jsp method=post TBODY TR TD width=80 height=30信件標(biāo)題:FONT color=#ff0000*/FONT/TD TDINPUT class=input id=topic name=topic /TD /TR TR T
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>
分享:jsp分頁類---統(tǒng)一使用一、建立數(shù)據(jù)庫分頁的類 package newsbean; import java.sql.*; public class DBConnection{ //這里使用ms jdbc String sDBDriver = com.microsoft.jdbc.sqlserver.SQLServerDriver; //指定數(shù)據(jù)庫名/url private final String url = jdbc:microsoft:sqlse
- jsp response.sendRedirect不跳轉(zhuǎn)的原因分析及解決
- JSP指令元素(page指令/include指令/taglib指令)復(fù)習(xí)整理
- JSP腳本元素和注釋復(fù)習(xí)總結(jié)示例
- JSP FusionCharts Free顯示圖表 具體實(shí)現(xiàn)
- 網(wǎng)頁模板:關(guān)于jsp頁面使用jstl的異常分析
- JSP頁面中文傳遞參數(shù)使用escape編碼
- 基于jsp:included的使用與jsp:param亂碼的解決方法
- Java Web項(xiàng)目中連接Access數(shù)據(jù)庫的配置方法
- JDBC連接Access數(shù)據(jù)庫的幾種方式介紹
- 網(wǎng)站圖片路徑的問題:絕對(duì)路徑/虛擬路徑
- (jsp/html)網(wǎng)頁上嵌入播放器(常用播放器代碼整理)
- jsp下顯示中文文件名及絕對(duì)路徑下的圖片解決方法
JSP教程Rss訂閱編程教程搜索
JSP教程推薦
猜你也喜歡看這些
- Windows下JSP開發(fā)環(huán)境的配置
- 使用JSP開發(fā)WebMail系統(tǒng)
- Java Web項(xiàng)目中連接Access數(shù)據(jù)庫的配置方法
- JSP進(jìn)行數(shù)據(jù)庫連接的實(shí)例
- Struts初級(jí)教程(4)-對(duì)國際化的支持
- 淺析JSP分頁教程
- 網(wǎng)頁無閃自動(dòng)局部刷新實(shí)例
- 詳細(xì)講解Linux系統(tǒng)下JDK、Tomcat的安裝
- JSP中 Session和作用域的使用
- Apache Tomcat 5.5部署jsp項(xiàng)目總結(jié)之——發(fā)布JSP應(yīng)用程序
- 相關(guān)鏈接:
- 教程說明:
JSP教程-jsp自動(dòng)生成靜態(tài)文件(html)
。