DengRuServer.java
- Java code
package DengRuServer;import java.io.*;import java.sql.*;import java.sql.Date;import java.text.*;import java.util.*;import javax.servlet.*;import javax.servlet.http.*;public class DengRuServer extends HttpServlet { String user,neirong,yanzhengma; public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Connection conn=null; response.setCharacterEncoding("utf-8"); response.setContentType("text/html;charset=utf-8"); PrintWriter out = response.getWriter(); user=request.getParameter("user"); //通过ID获取前台的昵称 neirong=request.getParameter("neirong"); yanzhengma=request.getParameter("yanzhengma"); System.out.println("用户名:"+user+"内容:"+neirong); HttpSession session=request.getSession(); //String code1=(String)session.getAttribute("code"); //if(yanzhengma.equals(code1)) //验证码正确执行 SimpleDateFormat matter=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String date=matter.format(new Date(1000)); System.out.println("读取时间"+date); String sql="insert into shiyichanglang values('"+neirong+"','"+date+"','"+user+"')"; try { conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/sss","root","hin19920309"); System.out.println("连接数据库成功"); Statement sta=conn.createStatement(); int rs=sta.executeUpdate(sql); System.out.println("数据插入成功"); } catch (SQLException e) { e.printStackTrace(); } String returnValues="<div><input name=user type=text>"; returnValues=returnValues+neirong; returnValues=returnValues+"</input></div>"; out.write(returnValues); System.out.println("数据插入成功"); /*}else{ //验证码错误执行 String returnValues="alert('验证码错误!')"; response.getWriter().write(returnValues); } out.flush(); out.close();*/ } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doGet(request, response); }}
shiyichanglang.jsp
- VBScript code
<%@page contentType="text/html" pageEncoding="UTF-8"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><link href="css\Style_135.css" rel="stylesheet" type="text/css" /><title>完全训练--诗意长廊</title><style>#gn{width:100%;height:30px;float:right;clear: both;text-align:right;padding-right:8px;padding-top:5px;background-color: #FFFFFF;filter:alpha(opacity=35);color:#000000;}#gn table { text-align:right;}#gn td { color:#000000;}#gn a{color:#000000;}</style></head><body topmargin=0 leftmargin=0><div id="menu" class='d'><TABLE><TR><TD><ul><li ><a href="shiyichanglang\01.html" target=list >欣赏作品一</a></li><li ><a href="03.html" target=list>欣赏作品二</a></li><li ><a href="05.html" target=list>欣赏作品三</a></li><li ><a href="06.html" target=list>欣赏作品四</a></li></ul></TD></TR></TABLE></div><TABLE><TR><TD><iframe frameBorder=0 marginHeight=0 marginWidth=0 scrolling=auto src=shiyichanglang\01.html width=800 height=550 name=list></iframe> </td> </tr></table><br><table width="100%" border="0" cellspacing="10" cellpadding="0"> <tr> <td width="20%" height="234"> </td> <td width="62%" align="left" valign="top"><form name="form1"> <table width="100%" border="0" cellspacing="10" cellpadding="0"> <tr> <td width="8%">昵称:</td> <td colspan="2"><input name="user" type="text" id="user" size="30" maxlength="32"></td> <td width="37%"> </td> <td width="15%"> </td> </tr> <tr> <td height="53">密码:</td> <td colspan="2"><input name="password" type="password" id="password" size="30" maxlength="32"></td> <td>路人评论可不用密码 </td> <td> </td> </tr> <tr> <td height="38">验证码:</td> <td width="12%"><input name="yanzhengma" type="text" id="yanzhengma" size="10" maxlength="4"></td> <td width="28%"><img border=0 src="image.jsp"></td> <td> </td> <td> </td> </tr> <tr> <td valign="top">内容:</td> <td colspan="3"><textarea name="neirong" id="neirong" cols="50" rows="10"></textarea></td> <td> </td> </tr> <tr> <td height="26"> </td> <td><input type="button" name="tijiao" id="tijiao" value="发表留言" onClick=createXMLHttpRequest()></td> <td><input type="button" name="quxiao" id="quxiao" value="取消"></td> <td> </td> <td> </td> </tr> </table> </form></td> <td width="18%"> </td> </tr></table><div id="pinglun"></div></body><script charSet="utf-8"> var httprequest; function createXMLHttpRequest() { alert("成功访问函数createXMLHttpRequest()"); if (window.XMLHttpRequest) { httprequest = new XMLHttpRequest(); } else if (window.ActiveXObject) { httprequest = new ActiveXObject("Microsoft.XMLHTTP"); } url="dengruserver.do"; httprequest.open('GET', url, true); httprequest.onreadystatechange = OnStatusChange; httprequest.send(); } function OnStatusChange() { if (httprequest.readyState == 4) // 完全接受 { if (httprequest.status == 200) // 服务器已经成功响应 { alert("访问服务器成功"); document.getElementById('pinglun').innerHTML = httprequest.responseText; } else // 访问出错 { alert(httprequest.responseText); alert("访问出错"); } } }</script></html>