哪个有关于JSP生成静态页面的帮助文档及说明的电子书,秀出来,谢谢了 生成静态页面的模板,就是最好的例子能给我发一份吗?[email protected]共同研究一下 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 有两种方式,一是用过滤器用setvlet实现另外一种是用类url实现。 都在这了,看懂了再修改自己用:内容虽然不是太全,不过你应该能看懂是怎么回事。因为后台的JAVABEAN挺多,我只分了重要的出来,你改一下应该可以完成。参考一下吧摸版是这样定义的:news.template<html><head><title>Untitled Document</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$> 发布时间:<font color=#ff0000><$date$></font></td> </tr> <tr> <td><$content$> </td> </tr></table></body></html>一个生成HTML的类:import java.io.*;public class WriteHtml{ public WriteHtml() { } public static void save(String s, String s1, String s2) throws WriteFileException { try { a(s1); FileOutputStream fileoutputstream = new FileOutputStream(s1 + s2); byte abyte0[] = s.getBytes(); fileoutputstream.write(abyte0); fileoutputstream.close(); } catch(IOException ioexception) { throw new WriteFileException(); } } private static void a(String s) { File file = new File(s); if(!file.exists()) file.mkdirs(); }}一个读取摸版的类:import java.io.*;public class ReadTemplates{ private static String _fldif = null; private static Object a = new Object(); public ReadTemplates() { } public static String getTlpContent(String s) throws ReadTemplateException { if(_fldif == null) synchronized(a) { if(_fldif == null) try { System.out.println("+++++++++++++"); _fldif = a(s); } catch(ReadTemplateException readtemplateexception) { throw new ReadTemplateException("模板信息读取失败。"); } } return _fldif; } private static synchronized String a(String s) throws ReadTemplateException { String s1 = null; try { FileInputStream fileinputstream = new FileInputStream(s); int i = fileinputstream.available(); byte abyte0[] = new byte[i]; fileinputstream.read(abyte0); fileinputstream.close(); s1 = new String(abyte0); } catch(IOException ioexception) { throw new ReadTemplateException(); } return s1; }}jsp文件:<%@ page contentType="text/html; charset=gb2312"%><%@ include file="/inc.jsp"%><%String[] flag = {"<$title$>","<$date$>","<$author$>","<$content$>"};String title=request.getParameter("title");String content=request.getParameter("content");String editer="admin";//Session.getAttribute("s_userName");int classid=Integer.parseInt(request.getParameter("class"));String filePath = "";filePath = application.getRealPath("./adminroot/news.template");String templateContent;try{ templateContent = ReadTemplates.getTlpContent(filePath);}catch(ReadTemplateException e){ throw new Exception("模板信息读取失败。请联系系统管理员。");}templateContent = ReplaceAll.replace(templateContent,flag[0],title);templateContent = ReplaceAll.replace(templateContent,flag[1],GetDate.getStringDate());templateContent = ReplaceAll.replace(templateContent,flag[2],editer);templateContent = ReplaceAll.replace(templateContent,flag[3],content);// 根据时间得文件名与路径名Calendar calendar = Calendar.getInstance();String fileName = String.valueOf(calendar.getTimeInMillis()) +".shtml";String pathName = application.getRealPath("./news")+"\\"+ calendar.get(Calendar.YEAR) + "\\"+ (calendar.get(Calendar.MONTH)+1) +"\\"+ calendar.get(Calendar.DAY_OF_MONTH)+"\\"; try{ WriteHtml.save(templateContent,pathName,fileName);}catch(WriteFileException we){ throw new Exception("操作失败!");}%> try { URL url = new URL("http://www.sina.com"); URLConnection uc = url.openConnection(); InputStream is = uc.getInputStream(); BufferedReader br = new BufferedReader(new InputStreamReader(is)); while (br.ready()) { str += br.readLine() + "\n"; } is.close(); } catch (IOException e) { e.printStackTrace(); } 搜索时关键词描红原理 如何通过XML Schema简单校验XML字符串 HTTP Status 404 .JSP通过数据源访问数据库时出错!!!! jsp如何上传附件到数据库中,如何下载呀?急急急 哪里有jsf下载 在不知道用户需要上传几个文件的情况下,如何在设计阶段使用一个文件上传表单来实现多文件上传?并且要把文件名存入数据库!想了好几个办 来拿分了,100分求个建议:) WEB 怎么做个选择文件夹的按钮呢? freemarker怎么判断变量是否等于字符串? 如何保存JSP网页为HTML文件。并保存网页中的图片。 退出时如何使session失效呢
一是用过滤器用setvlet实现
另外一种是用类url实现。
news.template<html>
<head>
<title>Untitled Document</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$> 发布时间:<font color=#ff0000><$date$></font></td>
</tr>
<tr>
<td><$content$>
</td>
</tr></table>
</body>
</html>一个生成HTML的类:
import java.io.*;public class WriteHtml
{ public WriteHtml()
{
} public static void save(String s, String s1, String s2)
throws WriteFileException
{
try
{
a(s1);
FileOutputStream fileoutputstream = new FileOutputStream(s1 + s2);
byte abyte0[] = s.getBytes();
fileoutputstream.write(abyte0);
fileoutputstream.close();
}
catch(IOException ioexception)
{
throw new WriteFileException();
}
} private static void a(String s)
{
File file = new File(s);
if(!file.exists())
file.mkdirs();
}
}一个读取摸版的类:
import java.io.*;public class ReadTemplates
{ private static String _fldif = null;
private static Object a = new Object(); public ReadTemplates()
{
} public static String getTlpContent(String s)
throws ReadTemplateException
{
if(_fldif == null)
synchronized(a)
{
if(_fldif == null)
try
{
System.out.println("+++++++++++++");
_fldif = a(s);
}
catch(ReadTemplateException readtemplateexception)
{
throw new ReadTemplateException("模板信息读取失败。");
}
}
return _fldif;
} private static synchronized String a(String s)
throws ReadTemplateException
{
String s1 = null;
try
{
FileInputStream fileinputstream = new FileInputStream(s);
int i = fileinputstream.available();
byte abyte0[] = new byte[i];
fileinputstream.read(abyte0);
fileinputstream.close();
s1 = new String(abyte0);
}
catch(IOException ioexception)
{
throw new ReadTemplateException();
}
return s1;
}}jsp文件:<%@ page contentType="text/html; charset=gb2312"%>
<%@ include file="/inc.jsp"%>
<%
String[] flag = {"<$title$>","<$date$>","<$author$>","<$content$>"};
String title=request.getParameter("title");
String content=request.getParameter("content");
String editer="admin";
//Session.getAttribute("s_userName");
int classid=Integer.parseInt(request.getParameter("class"));
String filePath = "";
filePath = application.getRealPath("./adminroot/news.template");
String templateContent;
try{
templateContent = ReadTemplates.getTlpContent(filePath);
}catch(ReadTemplateException e){
throw new Exception("模板信息读取失败。请联系系统管理员。");
}
templateContent = ReplaceAll.replace(templateContent,flag[0],title);
templateContent = ReplaceAll.replace(templateContent,flag[1],GetDate.getStringDate());
templateContent = ReplaceAll.replace(templateContent,flag[2],editer);
templateContent = ReplaceAll.replace(templateContent,flag[3],content);// 根据时间得文件名与路径名
Calendar calendar = Calendar.getInstance();
String fileName = String.valueOf(calendar.getTimeInMillis()) +".shtml";
String pathName = application.getRealPath("./news")+"\\"+ calendar.get(Calendar.YEAR) +
"\\"+ (calendar.get(Calendar.MONTH)+1) +"\\"+ calendar.get(Calendar.DAY_OF_MONTH)+"\\";
try{
WriteHtml.save(templateContent,pathName,fileName);
}catch(WriteFileException we){
throw new Exception("操作失败!");
}%>
URL url = new URL("http://www.sina.com");
URLConnection uc = url.openConnection();
InputStream is = uc.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
while (br.ready()) {
str += br.readLine() + "\n";
}
is.close();
} catch (IOException e) {
e.printStackTrace();
}