??xml version="1.0" encoding="utf-8" standalone="yes"?>
]]>
]]>
轉自Q?A >http://blueline.hit.edu.cn/ccs/blogs/loveme/archive/2006/03/03/1030.aspx
Z减轻服务器压力,原来的文章理pȝ由JSP文g的从数据库中取数据显C改为由jsp生成静态html文g后直接访问html文g。下面是一个简单的CZ
1.buildhtml.jsp
<%@ page contentType="text/html; charset=gb2312" import="java.util.*,java.io.*"%>
<%
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);//d模块文g
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);//替换掉模块中相应的地?BR> //out.print(templateContent);
// Ҏ旉得文件名
Calendar calendar = Calendar.getInstance();
String fileame = String.valueOf(calendar.getTimeInMillis()) +".html";
fileame = request.getRealPath("/")+fileame;//生成的html文g保存路径
FileOutputStream fileoutputstream = new FileOutputStream(fileame);//建立文g输出?BR> 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">authorQ?##author### </td>
</tr>
<tr>
<td>###content###
</td>
</tr>
</table>
</body>
</html>
最后作者以StrutsZQ介l了几种选择Ajax的场景:
1 现有的Struts应用E序要用AjaxQ请使用AjaxAnywhere
2 建立新的应用E序准备使用AjaxQ参考AppfuseQ它集成了DWR的Ajax
3 中期目标Q?使用一U支持Ajax的JSF的实玎ͼMyFaces或者Struts Shale
原文地址Q?A >http://blog.csdn.net/danny_xcz/archive/2006/03/03/614302.aspx