netbeans glassfish nullpointer服务器错误

时间:2016-01-27 12:56:33

标签: java html jsp netbeans glassfish

package Servlet;

import Manager.UserManager;
import Model.User;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import utils.IConstants;
import utils.StringUtils;

public class LoginServlet extends HttpServlet {

    /**
     * Processes requests for both HTTP <code>GET</code> and         <code>POST</code>
 * methods.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {String email = request.getParameter("email");
    String password = request.getParameter("password");

    if (StringUtils.isStringEmpty(email) || StringUtils.isStringEmpty(password)) {

        RequestDispatcher rd = request.getRequestDispatcher("/index.html");
        rd.forward(request, response);

    } else {

        UserManager uMgr = new UserManager();
        User user = uMgr.loginUser(email, password);
        if (user == null) {
            RequestDispatcher rd = request.getRequestDispatcher("/index.html");
            rd.forward(request, response);
        } else {
            request.getSession(true).setAttribute(IConstants.SESSION_KEY_USER, user);
            if (user.getUsertype().equals(IConstants.USER_TYPE_ADMIN)) {
                RequestDispatcher rd = request.getRequestDispatcher("/adminHome.jsp");
                rd.forward(request, response);
            } else if (user.getUsertype().equals(IConstants.USER_TYPE_GENERAL_USER)) {
                RequestDispatcher rd = request.getRequestDispatcher("/genUserHome.jsp");
                rd.forward(request, response);
            } else {
                RequestDispatcher rd = request.getRequestDispatcher("/index.html");
                rd.forward(request, response);
            }
        }
    }

}

// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/**
 * Handles the HTTP <code>GET</code> method.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    processRequest(request, response);
}

/**
 * Handles the HTTP <code>POST</code> method.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    processRequest(request, response);
}

/**
 * Returns a short description of the servlet.
 *
 * @return a String containing servlet description
 */
@Override
public String getServletInfo() {
    return "Short description";
}// </editor-fold>

}

当我们运行代码并尝试登录时,我们会继续这样做: 服务器错误500: “显示java.lang.NullPointerException”

尝试将HTML文本字段的内容传递给一个函数,该函数在数据库中搜索电子邮件和密码并返回用户类。

如果该用户类的类型为“admin”,则登录应该将他带到管理页面,但不是。

所有nullpointexceptions似乎都与将电子邮件和密码传递给用户管理器相关联,但是我已经测试了将db与变量电子邮件和密码匹配的特定值设置,但是我仍然遇到相同的错误。

非常感谢。

来自glassfish服务器的输出堆栈: http://pastebin.com/YC6GtviP

1 个答案:

答案 0 :(得分:0)

您遇到了很多SQL错误,因为无法找到数据库。根本问题可能是:

$scope.$watchCollection

这会阻止数据库的创建。