<!–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>
</tr>
<tr>
<td colspan=3><table align="center" width="100%" cellspacing="0" cellpadding="0" bordercolordark="#88a6dd" bordercolorlight="#88a6dd">
<tr>
<td align="center" bgcolor="#88a6dd"><input type="submit" value="提交留言"></td>
<td align="center"><a href="view_message.jsp"><font size=2>查看留言</font></a></td>
<td align="center" bgcolor="#88a6dd"><input type="reset" value="重新填写"></td>
</tr>
</table></td>
</tr>
</form>
</table></td>
</tr>
</table>
</body>
</html>
<html>
<head>
<title> message board </title>
</head>
<body>
<table width="60%" 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>
</tr>
<tr>
<td colspan=3><table align="center" width="100%" cellspacing="0" cellpadding="0" bordercolordark="#88a6dd" bordercolorlight="#88a6dd">
<tr>
<td align="center" bgcolor="#88a6dd"><input type="submit" value="提交留言"></td>
<td align="center"><a href="view_message.jsp"><font size=2>查看留言</font></a></td>
<td align="center" bgcolor="#88a6dd"><input type="reset" value="重新填写"></td>
</tr>
</table></td>
</tr>
</form>
</table></td>
</tr>
</table>
</body>
</html>
<!–view_message.jsp–>
<%@ page import="java.sql.*" %>
<html>
<head>
<title> show the message in the table </title>
</head>
<body>
<p align="center">所有访客留言</p>
<hr>
<%
try
{
class.forname("sun.jdbc.odbc.jdbcodbcdriver");
string url="jdbc:odbc:user_db";
connection con=drivermanager.getconnection(url,"insher","insher");
statement stm=con.createstatement();
resultset result=stm.executequery("select count(*) from message");
int message_count=0;
if(result.next())
{
message_count=result.getint(1);
result.close();
}
if(message_count>0)
{
result=stm.executequery("select * from message order by time desc");
while(result.next())
{
string title=result.getstring("title");
string name=result.getstring("name");
string mail=result.getstring("mail");
timestamp time=result.gettimestamp("time");
date date_time=new date(time.gettime());
time time_time=new time(time.gettime());
string content=result.getstring("content");
%>
<table width="100%" align="center" border=1 cellspacing="0" cellpadding="0" bordercolordark="#000000" bordercolorlight="#88a6dd">
<tr><td bgcolor="#88a6dd"><font size=2>主题:</font></td>
<td colspan=3><%=title%></td></tr>
<tr><td bgcolor="#88a6dd"><font size=2>留言人:</font></td>
<td><%=name%></td><td bgcolor="#88a6dd"><font size=2>e-mail:</font></td>
<td>
<%
out.println("<a href=mailto:"+mail+">"+mail+"</a>");
%>
</td></tr>
<tr><td bgcolor="#88a6dd"><font size=2>留言时间:</font></td><td colspan=3>
<%
out.println("<font size=2>"+date_time+" "+time_time+"</font>");
%>
</td></tr>
<tr><td align="center">
<%
out.println("("+message_count+")");
%>
</td>
<td colspan=3><%=content%>
</td></tr>
</table>
<%
out.println("<hr>");
message_count–;
}
result.close();
con.close();
}
else
{
out.println("目前还没有任何留言!");
con.close();
}
} catch(exception e)
{out.println(e);}
%>
<p align="center"><a href="../message/index.html">我要留言</a></p>
</body>
</html>
<!–view_message.jsp–>
<%@ page import="java.sql.*" %>
<html>
<head>
<title> show the message in the table </title>
</head>
<body>
<p align="center">所有访客留言</p>
<hr>
<%
try
{
class.forname("sun.jdbc.odbc.jdbcodbcdriver");
string url="jdbc:odbc:user_db";
connection con=drivermanager.getconnection(url,"insher","insher");
statement stm=con.createstatement();
resultset result=stm.executequery("select count(*) from message");
int message_count=0;
if(result.next())
{
message_count=result.getint(1);
result.close();
}
if(message_count>0)
{
result=stm.executequery("select * from message order by time desc");
while(result.next())
{
string title=result.getstring("title");
string name=result.getstring("name");
string mail=result.getstring("mail");
timestamp time=result.gettimestamp("time");
date date_time=new date(time.gettime());
time time_time=new time(time.gettime());
string content=result.getstring("content");
%>
<table width="100%" align="center" border=1 cellspacing="0" cellpadding="0" bordercolordark="#000000" bordercolorlight="#88a6dd">
<tr><td bgcolor="#88a6dd"><font size=2>主题:</font></td>
<td colspan=3><%=title%></td></tr>
<tr><td bgcolor="#88a6dd"><font size=2>留言人:</font></td>
<td><%=name%></td><td bgcolor="#88a6dd"><font size=2>e-mail:</font></td>
<td>
<%
out.println("<a href=mailto:"+mail+">"+mail+"</a>");
%>
</td></tr>
<tr><td bgcolor="#88a6dd"><font size=2>留言时间:</font></td><td colspan=3>
<%
out.println("<font size=2>"+date_time+time_time+"</font>");
%>
</td></tr>
<tr><td align="center">
<%
out.println("("+message_count+")");
%>
</td>
<td colspan=3><%=content%>
</td></tr>
</table>
<%
out.println("<hr>");
message_count–;
}
result.close();
con.close();
}
else
{
out.println("目前还没有任何留言!");
con.close();
}
} catch(exception e)
{out.println(e);}
%>
<p align="center"><a href="../message/index.html">我要留言</a></p>
</body>
</html>