[求助]添加简讯的代码,出错。。。。
下面是添加简讯的代码<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*,java.io.*"%>
<%
String NewId=request.getParameter("NewId");
String Headline=request.getParameter("Headline");
String Date=request.getParameter("Date");
String contain=request.getParameter("contain");
String
containAll="<html><head><title>"+Headline+"</title></head><body><%@
include
file="IncludeHead.jsp"%><pre>"+contain+"</pre><%@
include file="IncludeCauda.jsp"%></body></html>";
//这句是生成一个HTML页面并在上面插上头和尾,不知道写的对不对
char c[]=containAll.toCharArray();
String fileName=NewId+".html";
String URL="gonggao\\"+fileName;
File f=new File("C:\Program Files\Apache Software Foundation\Tomcat
5.5\webapps\ROOT\NSA\gonggao",fileName);
//这有没有相对路径的写法
FileWriter o=new FileWriter(f);
o.write(c,0,c.length);
o.close();
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(Exception e){
out.println("驱动程序未找到!");
}
Connection con=DriverManager.getConnection("jdbc:odbc:NewSchoolArea");
Statement conn=con.createStatement();
int flag=conn.executeUpdate("insert into 公告(公告号,公告名,公告地址,日期) values('"+NewId+"','"+Headline+"','"+URL+"','"+Date"')");
if(flag>0)
{
%>
<script language="javascript">
window.location ="AddOk.jsp";
</script>
<%}
else
{%>
<script language="javascript">
alert("添加简讯失败,请重新添加!");
history.back();
</script>
<%}
con.close();
conn.close();
%>
[此贴子已经被作者于2007-3-22 16:13:31编辑过]