猿问

关于回复,留言功能的问题,能帮忙看看哪里错了么?

message.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8" import="java.sql.*"%>

                                   <!-- 用于显示留言 -->

<form name="form3" method="post" action="msgs.jsp">

<textarea name="text2" rows="8" cols="40" >


</textarea>

<br>


<input type="reset"  value="清空">

&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp

&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 

<input type="submit" value="发表"  >

<!-- <br>

请输入你要回复的ID:<input name="id" type="text" value="回复"> -->  

</form>


<% 

    /* String text=new String(request.getParameter("text2").getBytes("ISO-8859-1"),"UTF-8");  */

    /* session.setAttribute("text2",text); */

     String name7=(String)session.getAttribute("visitorName"); 

    /*  String id=new String(request.getParameter("id").getBytes("ISO-8859-1"),"UTF-8");  */


try {

Class.forName("com.mysql.jdbc.Driver");

} catch (ClassNotFoundException e) {

System.out.println("加载数据库驱动时抛出异常,内容如下:"); 

e.printStackTrace();

}  

  Connection conn4 = DriverManager.getConnection("jdbc:mysql://localhost:3306/visitor","root","123456");

  Statement stmt4=conn4.createStatement();

  Statement stmt5=conn4.createStatement();

  ResultSet rs6=stmt4.executeQuery("select * from message ");

  ResultSet rs7=stmt5.executeQuery("select * from replyed ");

  

  while(rs6.next()){

 out.println("id:"+rs6.getString(1)+"用户"+rs6.getString(2)+"留言内容:"+rs6.getString(3)+"日期"+rs6.getString(4));

 out.println("<br>");

 out.println("<form action='reply.jsp' method='post'>");

 out.println("<textarea name='text3' rows='3' cols='40'>");

 out.println("</textarea>");

 out.println("<br>");

 out.println("<input name='replyName' type='hidden' value='rs6.getString(1)'> ");

 out.println("<input type='reset' value='清空'> ");

 out.println("<input type='submit' value='回复'> ");

 out.println("</form>");

 while(rs7.next()){

 out.println("<br>");

 out.println("id:"+rs7.getString(1)+"用户"+rs7.getString(2)+"回复内容:"+rs7.getString(3)+"日期"+rs7.getString(4)+"回复ID"+rs7.getString(5));

  }  

  }

  stmt4.close();

  stmt5.close();

  conn4.close();

  rs6.close();

%>

msgs.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8" import="java.sql.*"%>

                                    <!--  将留言存入数据库并返回message.jsp显示 -->

    

<% 

    String text=new String(request.getParameter("text2").getBytes("ISO-8859-1"),"UTF-8");

    String name7=(String)session.getAttribute("visitorName");

    

    

    /* String text3=(String)session.getAttribute("text2"); */


try {

Class.forName("com.mysql.jdbc.Driver");

} catch (ClassNotFoundException e) {

System.out.println("加载数据库驱动时抛出异常,内容如下:"); 

e.printStackTrace();

}  Connection conn4 = DriverManager.getConnection("jdbc:mysql://localhost:3306/visitor","root","123456");

  Statement stmt4=conn4.createStatement();

  int rs5=stmt4.executeUpdate("insert into message(name,text)values('"+name7+"','"+text+"')");

  

  

  /* ResultSet rs6=stmt4.executeQuery("select * from message where name='"+name7+"' ");

  

  

  while(rs6.next()){

 out.println("id:"+rs6.getString(1)+"用户"+rs6.getString(2)+"留言内容:"+rs6.getString(3)+"日期"+rs6.getString(4));

 out.println("<br>");

  } */ 

  

  stmt4.close();

  conn4.close();

  /* rs6.close(); */





%>


   <jsp:forward page="message.jsp"/> 


reply.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8" import="java.sql.*" %>

                                  <!--  将回复存入数据库,并返回message.jsp中显示 -->

<%   

    String name7=(String)session.getAttribute("visitorName");

    String replyId=new String(request.getParameter("replyName").getBytes("ISO-8859-1"),"UTF-8");

    String replyText=new String(request.getParameter("text3").getBytes("ISO-8859-1"),"UTF-8"); 

    try {

    Class.forName("com.mysql.jdbc.Driver");

    } catch (ClassNotFoundException e) {

    System.out.println("加载数据库驱动时抛出异常,内容如下:"); 

    e.printStackTrace();

    }  

        Connection conn7 = DriverManager.getConnection("jdbc:mysql://localhost:3306/visitor","root","123456");

    Statement stmt7=conn7.createStatement();

    int rs7=stmt7.executeUpdate("insert into replyed(name,message,replyId)values('"+name7+"','"+replyText+"','"+replyId+"')");

    stmt7.close();

    conn7.close();

%>

<jsp:forward page="message.jsp"/> 



//////session.setAttribute("visitorName",name6);

/////上边的visitorName是从这里来的,在用户登陆的时候提取用户的name6这个参数

这个问题卡了我两天了,自己一个人想想不出来,,厚着脸皮看看有没有人能帮我看看该怎么改,谢谢了

慕工程6005648
浏览 1148回答 0
0回答
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答