JSP与SQL SERVER的留言本

2008-02-23 09:59:18来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

<!--add_message.JSP-->
<%@ page import="Java.sql.*" %>
<HTML>
<HEAD>
<TITLE>add 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>
<TITLE>add 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>
<TR>
<TD>主题:</TD>
<TD bgcolor="#88a6dd"><input type="text" name="title" size=25></TD>
</TR>
<TR>
<TD valign="top" bgcolor="#88a6dd">留言:</TD>
<TD><textarea name="content" rows=7 cols=25></textarea></TD>

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:刚运行了 Azureus ,给我的感觉是这界面真不象是Java 写的,发誓

下一篇:java中文问题-浅析