jsp将数据直接写成HTML文件
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.io.*,java.sql.Date,java.util.*,java.text.*"%>
<%@include file="trans.jsp"%>
<html>
<head>
<title>将数据写入文件</title>
</head>
<body>
<form method="post" action="WriteData.jsp">
主题:<INPUT name=subject size=80><br>
内容:<textarea name=content cols=80 rows=20 ></textarea>
<br>
<input name="submit" type="submit" value="确 认">
<input name="reset" type="reset" value="重 填">
</form>
<%
String path=request.getRealPath(".");
Calendar cal = Calendar.getInstance();
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
String Files=formatter.format(cal.getTime());
FileWriter fw=new FileWriter(path + "\\"+Files+".html");
fw.write("<html><head><title>"+trans(request.getParameter("subject"))+"</title>");
fw.write("<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>");
fw.write("<META HTTP-EQUIV='Pragma' CONTENT='no-cache'>");
fw.write("</head><body leftmargin='0' topmargin='0'>");
fw.write("<table border=0 cellspacing=0 cellpadding=0 width='100%'>");
fw.write("<tr><td align=left valign=top><table border=0 cellspacing=0 cellpadding=0 width=770 align=center>");
fw.write("<tr><td width='777'><table border=0 cellspacing=0 cellpadding=0 width=770><tr><td valign=top width=680> <br>");
fw.write("<table border=0 cellspacing=0 cellpadding=0 width='100%'>");
fw.write("<tr> <td align=center>");
fw.write("<table border=0 cellspacing=0 cellpadding=0 width='95%'>");
fw.write("<tr>");
fw.write("<td align=center></td>");
fw.write("</tr><tr><td align=center height=25 valign=top><table width=100% bgcolor='#D0C8C8'>");
fw.write("<tr><td width='20%'>>>新闻中心>>正文</td>");
fw.write("</tr> </table> <br>");
fw.write("<b>"+trans(request.getParameter("subject"))+"</b>");
fw.write(" <hr><span class=9n>"+new java.util.Date()+"</span></td>");
fw.write("</tr> <tr> <td align=left><div align=center></div>");
fw.write("<br><p class='wtext'>"+trans(request.getParameter("content"))+" </p>");
fw.write("<div align=right></div></td> </tr>");
fw.write("<tr><td align=center><br>");
fw.write("<div align=center><a href='javascript:window.close()' class=tl>【关闭窗口】</a></td></tr>");
fw.write("</table> </td> </tr> </table></td>");
fw.write("<td width=150 valign=top bgcolor='#ffffff' align=left>");
fw.write("<p> </p>");
fw.write("</td></tr></table> </td></tr><tr><td>");
fw.write("<table border=0 height=4 cellspacing=0 cellpadding=0 width='100%'>");
fw.write("<tr><td width=108 bgcolor='#003564'> </td>");
fw.write("<td rowspan='2'><table width=100% border=0 cellspacing=0 cellpadding=0>");
fw.write(" <tr><td height=1 bgcolor='#003564'> </td>");
fw.write(" </tr><tr><td height=3 bgcolor='#cc0001'> </td>");
fw.write("</tr> </table> </td></tr><tr><td bgcolor='#CC0001'> </td>");
fw.write("</tr></table></td></tr>");
fw.write("<tr><td> </td> </tr>");
fw.write("<tr> <td> <table width='770' border='0' cellspacing='0' cellpadding='0'>");
fw.write("<tr bgcolor='#000000' valign='top'> <td bgcolor='#E7E7E7'> </td>");
fw.write(" </tr> </table></td> </tr> </table> </td> </tr></table></body></html>");
fw.close();
out.println("数据已经插入!");
%>
</body>
</html>
<%@ page import="java.io.*,java.sql.Date,java.util.*,java.text.*"%>
<%@include file="trans.jsp"%>
<html>
<head>
<title>将数据写入文件</title>
</head>
<body>
<form method="post" action="WriteData.jsp">
主题:<INPUT name=subject size=80><br>
内容:<textarea name=content cols=80 rows=20 ></textarea>
<br>
<input name="submit" type="submit" value="确 认">
<input name="reset" type="reset" value="重 填">
</form>
<%
String path=request.getRealPath(".");
Calendar cal = Calendar.getInstance();
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
String Files=formatter.format(cal.getTime());
FileWriter fw=new FileWriter(path + "\\"+Files+".html");
fw.write("<html><head><title>"+trans(request.getParameter("subject"))+"</title>");
fw.write("<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>");
fw.write("<META HTTP-EQUIV='Pragma' CONTENT='no-cache'>");
fw.write("</head><body leftmargin='0' topmargin='0'>");
fw.write("<table border=0 cellspacing=0 cellpadding=0 width='100%'>");
fw.write("<tr><td align=left valign=top><table border=0 cellspacing=0 cellpadding=0 width=770 align=center>");
fw.write("<tr><td width='777'><table border=0 cellspacing=0 cellpadding=0 width=770><tr><td valign=top width=680> <br>");
fw.write("<table border=0 cellspacing=0 cellpadding=0 width='100%'>");
fw.write("<tr> <td align=center>");
fw.write("<table border=0 cellspacing=0 cellpadding=0 width='95%'>");
fw.write("<tr>");
fw.write("<td align=center></td>");
fw.write("</tr><tr><td align=center height=25 valign=top><table width=100% bgcolor='#D0C8C8'>");
fw.write("<tr><td width='20%'>>>新闻中心>>正文</td>");
fw.write("</tr> </table> <br>");
fw.write("<b>"+trans(request.getParameter("subject"))+"</b>");
fw.write(" <hr><span class=9n>"+new java.util.Date()+"</span></td>");
fw.write("</tr> <tr> <td align=left><div align=center></div>");
fw.write("<br><p class='wtext'>"+trans(request.getParameter("content"))+" </p>");
fw.write("<div align=right></div></td> </tr>");
fw.write("<tr><td align=center><br>");
fw.write("<div align=center><a href='javascript:window.close()' class=tl>【关闭窗口】</a></td></tr>");
fw.write("</table> </td> </tr> </table></td>");
fw.write("<td width=150 valign=top bgcolor='#ffffff' align=left>");
fw.write("<p> </p>");
fw.write("</td></tr></table> </td></tr><tr><td>");
fw.write("<table border=0 height=4 cellspacing=0 cellpadding=0 width='100%'>");
fw.write("<tr><td width=108 bgcolor='#003564'> </td>");
fw.write("<td rowspan='2'><table width=100% border=0 cellspacing=0 cellpadding=0>");
fw.write(" <tr><td height=1 bgcolor='#003564'> </td>");
fw.write(" </tr><tr><td height=3 bgcolor='#cc0001'> </td>");
fw.write("</tr> </table> </td></tr><tr><td bgcolor='#CC0001'> </td>");
fw.write("</tr></table></td></tr>");
fw.write("<tr><td> </td> </tr>");
fw.write("<tr> <td> <table width='770' border='0' cellspacing='0' cellpadding='0'>");
fw.write("<tr bgcolor='#000000' valign='top'> <td bgcolor='#E7E7E7'> </td>");
fw.write(" </tr> </table></td> </tr> </table> </td> </tr></table></body></html>");
fw.close();
out.println("数据已经插入!");
%>
</body>
</html>
Jason
2005-05-12 22:09:49
评论:2
阅读:2328
引用:0
是啊!
@2005-05-15 15:53:02 xiaosheng
起初我也是这样想的!后来想把所有的标题和具体文件的名称插入数据库,以方便动态作连接,可谁知道数据库老是出一些奇怪的问题!我就暂时告一段落了!
可以完善成独立的一个包
@2005-05-15 01:29:23 hofman
我想,这么做,应该有意义。
