日期:2014-05-18  浏览次数:20718 次

空指针问题,求解决方法,急啊
提交登入表单时,出现错误
  description The server encountered an internal error () that prevented it from fulfilling this request.

exception 

org.apache.jasper.JasperException: Exception in JSP: /pages/login.jsp:25

22: ResultSet rs=jdbc.executeQuery(sql);
23: //out.print(sql);
24: //out.close();
25: if(rs.next()){
26: user_Id=rs.getInt("user_Id");
27: uname=rs.getString("uname");
28: cname=rs.getString("cname");


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:504)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


root cause 

java.lang.NullPointerException
org.apache.jsp.pages.login_jsp._jspService(login_jsp.java:78)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


note The full stack trace of the root cause is available in the Apache Tomcat/5.5.16 logs.



我知道是rs这个对象可能为空,我还用.next()的方法,但是问题是,我不知道怎么解决,请高手赐教!
  PS:数据库连好了没我也不知道



------解决方案--------------------
加断点 看sql语句是否正确 
正确的话 看你得数据库连接是否成功
------解决方案--------------------
rs是否为空 打印出来看一下 判断如果为空 直接返回!
我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.aiyiweb.com/java-web/317.html