Tomcat 8 java.lang.NullPointerException

时间:2015-07-10 18:37:55

标签: java jsp

当我尝试登录到托管的tomcat 8的Web应用程序时,我收到以下错误,但它与Glasssfish服务器的开发服务器工作正常。

错误:

java.lang.NullPointerException
com.pg.servlet.session.SQLHelper.ValidateUser(SQLHelper.java:71)
com.pg.servlet.session.LoginServlet.doPost(LoginServlet.java:42)
javax.servlet.http.HttpServlet service(HttpServlet.java:648)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

代码:

public class LoginServlet extends HttpServlet {

@Override
protected void doPost(HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException {

    String user = request.getParameter("username");
    String pwd = request.getParameter("password");
    String message = null;

    try {
        validated = SQLHelper.ValidateUser(user, SQLHelper.getEncryptedPassword(pwd));
    } catch (SQLException ex) {
        Logger.getLogger(LoginServlet.class.getName()).log(Level.SEVERE, null, ex);
    }

    if (validated == 1) {
        HttpSession session = request.getSession();
        session.setAttribute("user", user);
        request.getRequestDispatcher("/Pages/Welcome.jsp").forward(request, response);
    } else {
        message = "Either username or password is incorrect.";
        request.setAttribute("message", message);
        request.getRequestDispatcher("/Login.jsp").forward(request, response);
    }
}
}

帮助代码:

 public static int ValidateUser(String Username, String Pwd)
            throws SQLException {
        Connection dbConnection = null;
        CallableStatement callableStatement = null;
        int result = 0;

        String insertStoreProc = "{call ValidateUser(?,?,?)}";

        try {
            dbConnection = getDBConnection();
            callableStatement = dbConnection.prepareCall(insertStoreProc);

            callableStatement.setString(1, Username);
            callableStatement.setString(2, Pwd);
            callableStatement.registerOutParameter(3, java.sql.Types.INTEGER);

            callableStatement.executeUpdate();
            result = (int) callableStatement.getInt(3);
        } catch (SQLException e) {
        } finally {

            if (callableStatement != null) {
                callableStatement.close();
            }

            if (dbConnection != null) {
                dbConnection.close();
            }
        }
        return result;
    }

0 个答案:

没有答案