<%@ page contentType="text/html; charset=gb2312" %>
<%@ page import="java.util.*,java.sql.*"%>
<%request.setCharacterEncoding("gb2312");%>
<%response.setCharacterEncoding("gb2312");%>
<%
String server="localhost";        
String dbname="lunwen";           
String user="root";   
String pass=""; 
String port="3306";    
String url ="jdbc:mysql://"+server+":"+port+"/"+dbname+"?user="+user+"&password="+pass+"&useUnicode=true&characterEncoding=gb2312"; 
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
Connection conn= DriverManager.getConnection(url); 
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet rs=null;
ResultSet rs2=null;
ResultSet rs3=null;
 %>
<%
String s_admin=(String)session.getAttribute("userid");
if(s_admin==null){
response.sendRedirect("checklogin.jsp");
}
%>
<%
String op = request.getParameter("op");
 if(op!=null&&op.equals("show")){
String s_currentpage =request.getParameter("currentpage");
String stuid = request.getParameter("studentid");
int deid = Integer.parseInt(request.getParameter("timuid"));
rs=stmt.executeQuery("select * from xuanti_final where Student_id='"+stuid+"'");
if(rs.next()){
response.sendRedirect("haschoiced.jsp");}
rs2=stmt.executeQuery("select * from xuanti_now where Student_id='"+stuid+"' and num=3");
if(rs2.next()){
response.sendRedirect("choicefull.jsp");}
rs3=stmt.executeQuery("select * from xuanti_now where Student_id='"+stuid+"' and Timu_id='"+deid +"'");
 if(rs3.next()){
response.sendRedirect("choiceerror.jsp");}
else{
stmt.executeUpdate("insert into xuanti_now(Student_id,Timu_id)"+
             "values('"+stuid+"','"+deid +"')");
 PreparedStatement choices_count = conn.prepareStatement("UPDATE timubiao SET Timu_now=Timu_now+1  WHERE Timu_id="+deid+ " ");
 PreparedStatement choices_num = conn.prepareStatement("UPDATE xuanti_now SET num=num+1  WHERE Student_id="+stuid+ " ");
choices_count.executeUpdate();
choices_num.executeUpdate();
response.sendRedirect("ShowMySubject.jsp");
   choices_count.close();
    choices_num.close(); 
 
  }
  }
   %>错误报告
org.apache.jasper.JasperException: An exception occurred processing JSP page /student/ChoiceSubject.jsp at line 3936: response.sendRedirect("choicefull.jsp");}
37: rs3=stmt.executeQuery("select * from xuanti_now where Student_id='"+stuid+"' and Timu_id='"+deid +"'");
38:  if(rs3.next()){
39: response.sendRedirect("choiceerror.jsp");}
40: else{
41: stmt.executeUpdate("insert into xuanti_now(Student_id,Timu_id)"+
42:              "values('"+stuid+"','"+deid +"')");
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:515)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:420)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause 我测试是在if(rs3.next()){存在的条件下测试出的错误报告

解决方案 »

  1.   

    高手们顺便帮我看看if {}else{}语句这样有错吗?急
      

  2.   

    在39行那加个try{}catch{}语句看看行不
      

  3.   

    这句response.sendRedirect("choiceerror.jsp");} 中的choiceerror.jsp看看你那个JSP文件是不是少了一个e,写成choicerror.jsp。
      

  4.   

    看了半天,没看出错误啊!
    楼主最好最后把数据集对象等close吧
      

  5.   

    只要是if 和else条件的匹配问题,
    上面的只要检查3个resultset对象,3个rs对象都没结果时执行插入操作。,具体怎么写各位给个意见,谢谢,
      

  6.   

    对啊你把 response.sendRedirect("choiceerror.jsp")注释一下

    排除法处理一下了。减少代码的复杂程度,容易看出问题的所在
      

  7.   

    问题解决了, 是if和else的路基次序有问题。改正后代码
    <%@ page contentType="text/html; charset=gb2312" language="java" import="java.util.*,java.sql.*" errorPage="" %><%request.setCharacterEncoding("gb2312");%>
    <%response.setCharacterEncoding("gb2312");%>
    <%
    String server="localhost";        
    String dbname="lunwen";           
    String user="root";   
    String pass=""; 
    String port="3306";    
    String url ="jdbc:mysql://"+server+":"+port+"/"+dbname+"?user="+user+"&password="+pass+"&useUnicode=true&characterEncoding=gb2312"; 
    Class.forName("org.gjt.mm.mysql.Driver").newInstance();
    Connection conn= DriverManager.getConnection(url); 
    Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
    ResultSet rs=null;
    ResultSet rs2=null;
    ResultSet rs3=null;
     %>
    <%
    String s_admin=(String)session.getAttribute("userid");
    if(s_admin==null){
    response.sendRedirect("checklogin.jsp");
    }
    %>
    <%
    String op = request.getParameter("op");
     if(op!=null&&op.equals("show")){
    String s_currentpage =request.getParameter("currentpage");
    String stuid = request.getParameter("studentid");
    int deid = Integer.parseInt(request.getParameter("timuid"));
    rs=stmt.executeQuery("select * from xuanti_final where Student_id='"+stuid+"'");if(rs.next()){
    response.sendRedirect("haschoiced.jsp");
    }
     else{
    rs2=stmt.executeQuery("select * from xuanti_now where Student_id='"+stuid+"' and num=3");
    if(rs2.next()){
    response.sendRedirect("choicefull.jsp");
    }else{
    rs3=stmt.executeQuery("select * from xuanti_now where Student_id='"+stuid+"' and Timu_id='"+deid +"'");
    if(rs3.next()){
    response.sendRedirect("choiceerror.jsp");
    }
    else{
    stmt.executeUpdate("insert into xuanti_now(Student_id,Timu_id)"+
                 "values('"+stuid+"','"+deid +"')");
     PreparedStatement choices_count = conn.prepareStatement("UPDATE timubiao SET Timu_now=Timu_now+1  WHERE Timu_id="+deid+ " ");
     PreparedStatement choices_num = conn.prepareStatement("UPDATE xuanti_now SET num=num+1  WHERE Student_id="+stuid+ " ");
    choices_count.executeUpdate();
    choices_num.executeUpdate();
    response.sendRedirect("ShowMySubject.jsp");
        choices_count.close();
        choices_num.close(); 
     stmt.close();
      }
      }
      }
      }
         %>