2024年5月24日发(作者:)
JSP生成静态HTML页面的几种方法
2008年04月12日 星期六 09:26
一、从数据库中取相应数据并替换掉模板中的对应标签,下面是一个简单的示例
<%@ page contentType="text/html; charset=gb2312"
import=".*,.*"%>
<%
try{
String title="This is Title";
String content="This is Content Area";
String editer="LaoMao";
String filePath = "";
filePath = lPath("/")+"test/";
//(filePath+"
");
String templateContent="";
FileInputStream fileinputstream = new FileInputStream(filePath);//读取
模块文件
int lenght = ble();
byte bytes[] = new byte[lenght];
(bytes);
();
templateContent = new String(bytes);
//(templateContent);
templateContent=eAll("###title###",title);
templateContent=eAll("###content###",content);
templateContent=eAll("###author###",editer);//
替换掉模块中相应的地方
//(templateContent);
// 根据时间得文件名
Calendar calendar = tance();
String fileame = f(eInMillis()) +".html";
fileame = lPath("/")+fileame;//生成的html文件保存路径
FileOutputStream fileoutputstream = new FileOutputStream(fileame);//
建立文件输出流
byte tag_bytes[] = es();
(tag_bytes);
();
}
catch(Exception e){
(ng());
}
%>
2.
###title### |
author:###author### |
###content### |
=======================================================
二、从动态页的URL获取相应页面内容并写入到文件
/*
* Created on 2006-3-4
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package ;
import edReader;
import ;
import tputStream;
import tream;
import treamReader;
import riter;
import LConnection;
发布者:admin,转转请注明出处:http://www.yc00.com/web/1716563737a2728354.html
评论列表(0条)