现在兄弟编写了一个jsp的程序,页面已经生成了,但是具体怎么成为静态页面呢??有没有相关的教程啊??或者类似的程序例子可以共享下?谢谢
解决方案 »
- 在IE浏览器中导出execl直接打开是在浏览器中打开,在线等........................
- request.getRemoteAddr()获得错误的IP如何解决
- 如果让过滤器 对以A01为前缀的资源进行过滤如对A01Action.do进行过滤
- 用jfreechart 画多轴图,现用版本是jfreechart-1.0.zip和jcommon-1.0.zip
- 使用filter,为什么index.jsp显示不出来?而registger.jsp可以.
- 大家一起来,jsp之session一问
- 关于response的问题
- 如何配置RESIN的resin.conf,使我能指向放BEAN的目录!!
- 关于新浪SAE上传war包限制50M
- javaweb基础问题,编译和调试
- jsp分页一定要把调用数据库的语句放jsp上吗?
- jsp生成静态页面后css样式文件丢失的问题
字段: id int 自动增长 , Title varchar(20) , Content varchar(200) , Author varchar(10) makeFile.jsp<%
Connection conn = DBconn.getConnection();
Statement stmt = conn.createStatement();
ResultSet Rs = stmt.executeQuery("select * from news");
System.out.println("success");%> <%
String filePath = request.getRealPath("/")+"template.htm"; System.out.println(filePath);
String templateContent;
FileInputStream fileinputstream = new FileInputStream(filePath);
int lenght = fileinputstream.available(); //available() 返回可以不受阻塞地从此文件输入流中读取的字节数。
byte bytes[] = new byte[lenght];fileinputstream.read(bytes); //read(byte[] b) 从此输入流中将最多 b.length 个字节的数据读入一个字节数组中。fileinputstream.close();
//templateContent = new String(bytes);
String title;
String content;
String author;
while(Rs.next())
{
templateContent = new String(bytes);//如果不用这句,则替换一次之后,templateContent中就没有#**#标志了。所以要重新生成
title = Rs.getString("Title");
content = Rs.getString("Content");
author = Rs.getString("Author");
out.println(title+"********"+content+"****"+author);
out.print("以下是模板内容:<br>"+templateContent+"<br> 以下是置换以后的html内容<br><hr>");
templateContent=templateContent.replaceAll("#title#",title);
templateContent=templateContent.replaceAll("#author#",author);//替换掉模块中相应的地方
templateContent=templateContent.replaceAll("#content#",content);// 根据时间得文件名
Calendar calendar = Calendar.getInstance();
String fileame = String.valueOf(calendar.getTimeInMillis()) +".html";
fileame = request.getRealPath("/")+"Html/"+fileame;//生成的html文件保存路径
out.print(templateContent);
FileOutputStream fileoutputstream = new FileOutputStream(fileame);//建立文件输出流
byte tag_bytes[] = templateContent.getBytes();
fileoutputstream.write(tag_bytes);
fileoutputstream.close();}if(conn!=null)
{
conn.close();
}
if(stmt!=null)
{
stmt.close();
}
%>//数据库连接文件import java.sql.*;
public class DBconn {
public DBconn() {
// TODO Auto-generated constructor stub
} public static Connection getConnection()
{
Connection conn = null;
try {
Class.forName("org.gjt.mm.mysql.Driver");
conn = DriverManager.getConnection("jdbc:mysql://" + "localhost" + "/" + "test" +
"?useUnicode=true&characterEncoding=GB2312","root","111111");
}
catch(Exception e)
{
e.printStackTrace();
}
return conn;
}
/*public static void main(String[] args) throws Exception
{
Connection con=getConnection();
System.out.println(con.isClosed());
}
*/
}// 模板文件template.htm
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>#title#</title>
</head><body>
<table width="380" height="107" border="0" cellpadding="0" cellspacing="1" bgcolor="#FFCC99">
<tr>
<td height="16" bgcolor="#FFCC99"><div align="center">#title#</div></td>
</tr>
<tr>
<td bgcolor="#FFFFFF">#content#</td>
</tr>
<tr>
<td height="13" align="right" bgcolor="#FFFFFF">#author#</td>
</tr>
</table>
</body>
</html>
<%
try{
String title="This is Title";
String content="This is Content Area";
String editer="LaoMao";
String filePath = "";
filePath = request.getRealPath("/")+"test/template.htm";
//out.print(filePath+"<br>");
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);
//out.print(templateContent);
templateContent=templateContent.replaceAll("###title###",title);
templateContent=templateContent.replaceAll("###content###",content);
templateContent=templateContent.replaceAll("###author###",editer);//替换掉模块中相应的地方
//out.print(templateContent);
// 根据时间得文件名
Calendar calendar = Calendar.getInstance();
String fileame = String.valueOf(calendar.getTimeInMillis()) +".html";
fileame = request.getRealPath("/")+fileame;//生成的html文件保存路径
FileOutputStream fileoutputstream = new FileOutputStream(fileame);//建立文件输出流
byte tag_bytes[] = templateContent.getBytes();
fileoutputstream.write(tag_bytes);
fileoutputstream.close();
}
catch(Exception e){
out.print(e.toString());
}%>2. template.htm<html>
<head>
<title>###title###</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<LINK href="../css.css" rel=stylesheet type=text/css>
</head><body>
<table width="500" border="0" align="center" cellpadding="0" cellspacing="2">
<tr>
<td align="center">###title###</td>
</tr>
<tr>
<td align="center">author:###author### </td>
</tr>
<tr>
<td>###content###
</td>
</tr></table>
</body>
</html>