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

编辑Tag赚U币
教程Tag:暂无Tag,欢迎添加,赚取U币!

推荐:用JSP来发送邮件
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信件标题:FONT color=#ff0000*/FONT/TD TDINPUT class=input id=topic name=topic /TD /TR TR T

jsp自动生成静态文件(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”程序会报错
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>
 

 

分享:jsp分页类---统一使用
一、建立数据库分页的类 package newsbean; import java.sql.*; public class DBConnection{ //这里使用ms jdbc String sDBDriver = com.microsoft.jdbc.sqlserver.SQLServerDriver; //指定数据库名/url private final String url = jdbc:microsoft:sqlse

来源:模板无忧//所属分类:JSP教程/更新时间:2010-04-19
相关JSP教程