当前位置: 代码迷 >> J2SE >> java.lang.NullPointerException,该怎么解决
  详细解决方案

java.lang.NullPointerException,该怎么解决

热度:191   发布时间:2016-04-24 15:58:39.0
java.lang.NullPointerException
<%@   page   contentType= "text/html;charset=gb2312 "   import= "java.sql.* "%>
<%@   page   pageEncoding= "gb2312 "   %>
<%   request.setCharacterEncoding( "gb2312 ");   %>
<jsp:useBean   id= "sqlBean "   class= "BYSJ.sqldata ">
</jsp:useBean> <html>
<html> <head> <title> </title> </head>
<body>
<%   String   username=request.getParameter( "username ");
      String   pwd=request.getParameter( "pwd ");   //smt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
        String   sql= "select   *   from   user   where   username= ' "+username+ " '   and   password= ' "+pwd+ " ' ";
        ResultSet   rs=sqlBean.executeQuery(sql);
        if(!rs.next())
        {
        String   errmsg= "error1 ";
        response.sendRedirect( "login.jsp?errmsg= "+errmsg);
        return;
        }
        request.getSession(true);
        String   chk= "true ";
        session.putValue( "Enter ",chk);
        session.putValue( "username ",rs.getString( "username "));
        response.sendRedirect( "manage.jsp ");
%>
</body> </html>
这段代码怎么出现java.lang.NullPointerException
                org.apache.jsp.BYSJ.logincheck_jsp._jspService(logincheck_jsp.java:65)
                org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
                javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
                org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
                org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
                org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
                javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

------解决方案--------------------
你输出一下看username和pwd的值是否得到了?
------解决方案--------------------
把你的SQL输出,到你的数据库客户端执行一下,看看是什么结果
  相关解决方案