« | July 2025 | » | 日 | 一 | 二 | 三 | 四 | 五 | 六 | | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | | | |
| 公告 |
暂无公告... |
Blog信息 |
blog名称: 日志总数:10 评论数量:25 留言数量:0 访问次数:89350 建立时间:2005年3月7日 |

| |
[xml]jsp生成静态的hmtl文件 文章收藏
guan1200 发表于 2005/6/2 11:51:14 |
jsp生成静态的hmtl文件
为了减轻服务器压力,将原来的文章管理系统由JSP文件的从数据库中取数据显示改为由jsp生成静态html文件后直接访问html文件。下面是一个简单的示例
1.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 = getServletContext().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 = getServletContext().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### </td>
</tr>
<tr>
<td>###content###
</td>
</tr>
</table>
</body>
</html> |
|
[xml]XMLHttp 方式实现无刷屏,在IE,FireFox 上测试通过 文章收藏
guan1200 发表于 2005/6/2 11:07:42 |
XMLHttp 方式实现无刷屏,在IE,FireFox 上测试通过
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/tr/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <style> html {background-color:#eeeeee} body { background-color:#ccffcc; font-family:Tahoma,Arial,Helvetica,sans-serif; font-size:12px; margin-left:15%; margin-right:15%; border:3px groove #006600; padding:15px } h1 { text-align:left; font-size:1.5em; font-weight:bold } </style> <script type="text/javascript"> // global flag var isIE = false;
// global request and XML document objects var req;
// retrieve XML document (reusable generic function); // parameter is URL string (relative or complete) to // an .xml file whose Content-Type is a valid XML // type, such as text/xml; XML source must be from // same domain as HTML file function loadXMLDoc(url) { // branch for native XMLHttpRequest object if (window.XMLHttpRequest) { req = new XMLHttpRequest(); req.onreadystatechange = processReqChange; req.open("GET", url, true); req.send(null); // branch for IE/Windows ActiveX version } else if (window.ActiveXObject) { isIE = true; req = new ActiveXObject("Microsoft.XMLHTTP"); if (req) { req.onreadystatechange = processReqChange; req.open("GET", url, true); req.send(); } } }
// handle onreadystatechange event of req object function processReqChange() { // only if req shows "loaded" if (req.readyState == 4) { // only if "OK" if (req.status == 200) { clearTopicList(); buildTopicList(); } else { alert("There was a problem retrieving the XML data:\n" + req.statusText); } } }
// invoked by "Category" select element change; // loads chosen XML document, clears Topics select // element, loads new items into Topics select element function loadDoc(evt) { // equalize W3C/IE event models to get event object evt = (evt) ? evt : ((window.event) ? window.event : null); if (evt) { // equalize W3C/IE models to get event target reference var elem = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null); if (elem) { try { if (elem.selectedIndex > 0) { loadXMLDoc(elem.options[elem.selectedIndex].value); } } catch(e) { var msg = (typeof e == "string") ? e : ((e.message) ? e.message : "Unknown Error"); &n |
|
« 1 ›
|