JSP页面自动生成html页面/或任何格式页面
2008-01-08 15:21
701 查看
先建立一个模本页面: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### </td>
</tr>
<tr>
<td>###content###
</td>
</tr>
</table>
</body>
</html>
=========================================
再写一个JSP页面: buildhtml.jsp
<%@ page contentType="text/html; charset=gb2312" import="java.util.*,java.io.*"%>
<%
try{
String title="李鹏的jsp生成静态html文件";
String content="小样,还搞不定你?";
String editer="hpsoft";
String filePath = "";
filePath = request.getRealPath("/")+"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);
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);//建立文件输出流
out.print("文件输出路径:<br>");
out.print(fileame);
byte tag_bytes[] = templateContent.getBytes();
fileoutputstream.write(tag_bytes);
fileoutputstream.close();
}
catch(Exception e){
out.print(e.toString());
}
%>
<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### </td>
</tr>
<tr>
<td>###content###
</td>
</tr>
</table>
</body>
</html>
=========================================
再写一个JSP页面: buildhtml.jsp
<%@ page contentType="text/html; charset=gb2312" import="java.util.*,java.io.*"%>
<%
try{
String title="李鹏的jsp生成静态html文件";
String content="小样,还搞不定你?";
String editer="hpsoft";
String filePath = "";
filePath = request.getRealPath("/")+"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);
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);//建立文件输出流
out.print("文件输出路径:<br>");
out.print(fileame);
byte tag_bytes[] = templateContent.getBytes();
fileoutputstream.write(tag_bytes);
fileoutputstream.close();
}
catch(Exception e){
out.print(e.toString());
}
%>
相关文章推荐
- JSP页面自动生成html页面或任何格式页面
- JSP页面自动生成html页面或任何格式页面
- JSP页面生成html页面或任何格式的页面
- jsp如何实现自动生成HTML页面
- 自动把动态的jsp页面(或静态html)生成PDF文档,并且上传至服务器
- JSP页面自动生成html页面
- Jsp中怎么把数据从数据库导出在页面直接生成html格式??
- ASP.Net自动批量生成HTML页面和索引页
- ASP.Net自动批量生成HTML页面和索引页
- JS自动生成动态HTML验证码页面,输入错误自动清空输入框
- 使Eclipse下支持编写HTML/JS/CSS/JSP页面的自动提示
- intellij 修改jsp 或者 html 自动加载页面变化
- 织梦DedeCMS信息发布员发布文章默认自动审核更新并生成HTML页面
- 利用Freemarker生成html静态页面,也可利用模版功能生成不同格式的文件
- 配置Eclipse编写HTML/JS/CSS/JSP页面的自动提示。
- JSP生成静态HTML页面的实践方法和设计思路
- 论文格式设置-页面设置、页眉页脚、自动生成目录等
- jsp生成html静态页面
- 使Eclipse下支持编写HTML/JS/CSS/JSP页面的自动提示。
- erb自动生成html页面一例