您的位置:首页 > 编程语言 > Java开发

Java生成html页面

2010-06-23 15:40 344 查看
<%@ page contentType="text/html; charset=gb2312" import="java.util.*,java.io.*"%>
<%
try{
UUID uuid = UUID.randomUUID(); //如果你不根据时候生成可以用UUID

String title="jsp生成静态html文件";
String content="小样,快出来吧html?";
String editer="webjxcom";
String filePath = "";
filePath = request.getRealPath("/")+"xxxx.jsp"; //这个页面为模板页面,支持多种格式
//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()) +".htm"; //可以根据时间生成路径
String fileame = String.valueOf(uuid) +".html";
fileame = request.getRealPath("/")+fileame;//生成的html文件保存路径
FileOutputStream fileoutputstream = new FileOutputStream(fileame);//建立文件输出流

//out.print(c+"**********************"+calendar.getTimeInMillis());
//response.sendRedirect(c);
byte tag_bytes[] = templateContent.getBytes();
fileoutputstream.write(tag_bytes);
fileoutputstream.close();
//response.sendRedirect(c);

}
catch(Exception e){
out.print(e.toString());
}
%>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: