J与SQL SERVER的留言本_JSP技巧_黑客防线网安服务器维护基地--Powered by WWW.RONGSEN.COM.CN

J与SQL SERVER的留言本

作者:黑客防线网安JSP教程基地 来源:黑客防线网安JSP教程基地 浏览次数:0

本篇关键词:#88a6dd/TD>bgcolorname
黑客防线网安网讯:      <!--add_message.jsp-->   <%@ page import="java.sql.*" %>   <HTML>   <HEAD>   <TITLE>add message into table </TITLE>   </HEAD>   <BODY>   <%   String nam...

      <!--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>
  

    黑客防线网安服务器维护方案本篇连接:http://www.rongsen.com.cn/show-16511-1.html
网站维护教程更新时间:2012-04-07 00:32:43  【打印此页】  【关闭
我要申请本站N点 | 黑客防线官网 |  
专业服务器维护及网站维护手工安全搭建环境,网站安全加固服务。黑客防线网安服务器维护基地招商进行中!QQ:29769479

footer  footer  footer  footer