Js|server
<!--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 ("Message person name cannot be empty!") ");
else if (title.length () ==0)
OUT.PRINTLN ("Message theme can not be empty!") ");
else if (content.length () ==0)
OUT.PRINTLN ("Message content can not be empty!") ");
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>
<!--add_message.jsp--
<%@ page import= "java.sql.*"%>
<HTML>
<HEAD>
<title >add message into table </TITLE>
</HEAD>
<BODY>
<%
String Name=request.getpara Meter ("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 ("message person name cannot be empty!") ");
Else if (title.length () ==0)
Out.println ("The message topic cannot be empty!") ");
Else if (content.length () ==0)
Out.println ("message content cannot be empty!") ");
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>
<!--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" > Guest Message Board </TD>
</TR>
<TR>
<td><table align= "center" border=1 cellspacing= "0" cellpadding= "0" bordercolordark= "#88a6dd" bordercolorlight= "#88a6dd" >
<form action= "add_message.jsp" >
<TR>
<TD> name:</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> Theme:</td>
<TD bgcolor= "#88a6dd" ><input type= "text" name= "title" Size=25></td>
</TR>
<TR>
<TD valign= "Top" bgcolor= "#88a6dd" > Message:</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= "Leave a Message" ></TD>
<TD align= "center" ><a href= "view_message.jsp" ><font size=2> View message </font></a></td >
<TD align= "center" bgcolor= "#88a6dd" ><input type= "reset" value= "re-fill" ></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" > Guest Message Board </TD>
</TR>
<TR>
<td><table align= "center" border=1 cellspacing= "0" cellpadding= "0" bordercolordark= "#88a6dd" bordercolorlight= "#88a6dd" >
<form action= "add_message.jsp" >
<TR>
<TD> name:</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> Theme:</td>
<TD bgcolor= "#88a6dd" ><input type= "text" name= "title" Size=25></td>
</TR>
<TR>
<TD valign= "Top" bgcolor= "#88a6dd" > Message:</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= "Leave a Message" ></TD>
<TD align= "center" ><a href= "view_message.jsp" ><font size=2> View message </font></a></td >
<TD align= "center" bgcolor= "#88a6dd" ><input type= "reset" value= "re-fill" ></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" > All guest Messages </p>
<%
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> theme:</font></td>
<TD colspan=3><%=title%></td></tr>
<TR><TD bgcolor= "#88a6dd" ><font size=2> message person:</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> message time: </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 ("message_count--;
}
Result.close ();
Con.close ();
}
Else
{
OUT.PRINTLN ("There are no messages yet!") ");
Con.close ();
}
catch (Exception e)
{out.println (e);}
%>
<p align= "center" ><a href= ". /message/index.html > I want to leave a message </a></p>
</body>
<!--view_message.jsp-->
<%@ page import= "java.sql.*"%>
<HTML>
<HEAD>
<TITLE> show the message in the table </TITLE>
</HEAD>
<BODY>
<p align= "center" > All guest Messages </p>
<%
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> theme:</font></td>
<TD colspan=3><%=title%></td></tr>
<TR><TD bgcolor= "#88a6dd" ><font size=2> message person:</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> message time: </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 ("message_count--;
}
Result.close ();
Con.close ();
}
Else
{
OUT.PRINTLN ("There are no messages yet!") ");
Con.close ();
}
catch (Exception e)
{out.println (e);}
%>
<p align= "center" ><a href= ". /message/index.html > I want to leave a message </a></p>
</body>