<!--add_message.jsp--
<%@ page import="java.sql.*" %
<HTML
<HEAD
<TITLEadd message into table </TITLE
</HEAD
<BODY
<%
String name=request.getParameter("name");
String mail=request.getParameter("mail");
String title=request.getParameter("title");
String content=request.getParameter("content");
if(name==null)
name="";
if(title==null)
title="";
if(content==null)
content="";
if(mail==null)
mail="";
if(name.length()==0)
out.println("留言人姓名不能为空!");
else if(title.length()==0)
out.println("留言主题不能为空!");
else if(content.length()==0)
out.println("留言内容不能为空!");
else
{
java.util.Date date=new java.util.Date();
String datetime=new Timestamp(date.getTime()).toString();
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url="jdbc:odbc:user_db";
Connection con=DriverManager.getConnection(url,"insher","insher");
PreparedStatement stm=con.prepareStatement("insert into message values(?,?,?,?,?)");
stm.setString(1,title);
stm.setString(2,name);
if(mail.length()==0)
stm.setString(3,null);
else stm.setString(3,mail);
stm.setString(4,datetime);
stm.setString(5,content);
try
{
stm.executeQuery();
} catch(Exception e)
{}
con.close();
}
catch (Exception e)
{}
%
<jsp:forward page="view_message.jsp" /
<%
}
%
</body
</html
<!--add_message.jsp--
<%@ page import="java.sql.*" %
<HTML
<HEAD
<TITLEadd message into table </TITLE
</HEAD
<BODY
<%
String name=request.getParameter("name");
String mail=request.getParameter("mail");
String title=request.getParameter("title");
String content=request.getParameter("content");
if(name==null)
name="";
if(title==null)
title="";
if(content==null)
content="";
if(mail==null)
mail="";
if(name.length()==0)
out.println("留言人姓名不能为空!");
else if(title.length()==0)
out.println("留言主题不能为空!");
else if(content.length()==0)
out.println("留言内容不能为空!");
else
{
java.util.Date date=new java.util.Date();
String datetime=new Timestamp(date.getTime()).toString();
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url="jdbc:odbc:user_db";
Connection con=DriverManager.getConnection(url,"insher","insher");
PreparedStatement stm=con.prepareStatement("insert into message values(?,?,?,?,?)");
stm.setString(1,title);
stm.setString(2,name);
if(mail.length()==0)
stm.setString(3,null);
else stm.setString(3,mail);
stm.setString(4,datetime);
stm.setString(5,content);
try
{
stm.executeQuery();
} catch(Exception e)
{}
con.close();
}
catch (Exception e)
{}
%
<jsp:forward page="view_message.jsp" /
<%
}
%
</body
</html
<!-- index.html --
<HTML
<HEAD
<TITLE message board </TITLE
</HEAD
<BODY
<TABLE width="90%" align="center" border=1 cellspacing="0" cellpadding="0" bordercolordark="#88a6dd" bordercolorlight="#88a6dd"
<TR
<TD align="center" bgcolor="#88a6dd"访客留言板</TD
</TR
<TR
<TD<TABLE align="center" border=1 cellspacing="0" cellpadding="0" bordercolordark="#88a6dd" bordercolorlight="#88a6dd"
<FORM ACTION="add_message.jsp"
<TR
<TD姓名:</TD
<TD bgcolor="#88a6dd"<input type="text" name="name" size=25</TD
</TR
<TR
<TD bgcolor="#88a6dd"E-mail:</TD
<TD bgcolor="#88a6dd"<input type="text" name="mail" size=25</TD
</TR <