小白请教
刚开始学JAVA WEB开发,买了本《java web 开发实战1200例》第5章的155例,带参数的查询,报错,具体代码如下:
<%@ page contentType="text/html;charset=GBK"%><%@ page import="java.sql.*" %><jsp:useBean id="db" class="com.jb.db.DB" scope="page"/><html> <head> <title>带参数的数据查询</title> <link rel="stylesheet" type="text/css" href="css/style.css"> </head> <script language="javascript"> function check(){ if(searchform.subsqlvalue.value==null||searchform.subsqlvalue.value==""){ alert("请输入查询的条件"); searchform.subsqlvalue.focus(); return false; } if(searchform.subsql.value=="user_age"){ if(isNaN(searchform.subsqlvalue.value)){ alert("输入的年龄必须为数字!"); searchform.subsqlvalue.focus(); return false; } } } </script> <body> <center> <form name="searchform" method="post" action="dosearchpart.jsp"> <table style="margin-top:200" width="300" border="1" cellpadding="0" cellspacing="0" bordercolor="black" bordercolorlight="black" bordercolordark="white"> <tr bgcolor="lightgrey" height="25"> <td align="center">用户名</td> <td align="center">性别</td> <td align="center">年龄</td> <td align="center">职务</td> <td align="center">资金</td> </tr> <% ResultSet rsall=db.getAllRs(); while(rsall.next()){ %> <tr> <td align="center"><%=rsall.getString("user_name")%></td> <td align="center"><%=rsall.getString("user_sex")%></td> <td align="center"><%=rsall.getInt("user_age")%></td> <td align="center"><%=rsall.getString("user_job")%></td> <td align="center"><%=rsall.getFloat("user_money")%></td> </tr> <% } %> <tr bgcolor="lightgrey"> <td align="center" colspan="5"> 查询类型: <select name="subsql"> <option value="user_name">用户名</option> <option value="user_sex">性别</option> <option value="user_age">年龄</option> <option value="user_job">职务</option> </select> <input type="text" name="subsqlvalue" size="17"> <input type="submit" name="searchpart" value="查询" onclick="return check()"> </td> </tr> </table> </form> </center> </body></html>
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:505)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:416)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
root cause
java.lang.NullPointerException
com.jb.db.DB.getAllRs(DB.java:47)
org.apache.jsp.index_jsp._jspService(index_jsp.java:99)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
请教了!
[解决办法]
com.jb.db.DB这个类有么?
[解决办法]
在DB类中写个main方法测试下getAllRs 看看报错不
我的异常网推荐解决方案:An exception occurred processing JSP page,http://www.myexception.cn/j2se/33144.html
我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.myexception.cn/java-web/317.html