JPA - NullPointerException при проверке журналов соединений - PullRequest
0 голосов
/ 28 апреля 2020

Я пытаюсь сделать страницу входа jsp с помощью сервлета. Я проверяю, есть ли в базе данных логин и пароль, и если да, то появится новая страница. jsp. Если нет, сообщение будет отображаться. Но когда я нажимаю Submit, возникает ошибка NullPointerException ...

У меня есть логин. jsp:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
  <form method="GET" name="Form" action="LoginServlet" style="width: 50%; margin: auto; background-color: whitesmoke; padding-bottom: 15px;">
    <h2 style="text-align: center; color: black; background-color: wheat;">Connexion</h2>
    <p style="text-align: center">
        Login: <input type="text" name="professor.email"/>
    </p>
    <p style="text-align: center">
        Password: <input type="text" name="professor.password"/>
    </p>
    <p style="text-align: center; width: 50%; margin: auto;">
        <input type="submit" name="Valider" value="Submit"/>
    </p>
    <p style="text-align: center">
        <%
            if(request.getAttribute("message") != null) {
        %>
                <%
                request.getAttribute("message");%>
                <%  
            }
        %>
    </p>
</form>
</body>
</html>

Мой логинServlet:

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    HttpSession session = request.getSession(true);
    String login = request.getParameter("professor.email")
    String pwd = request.getParameter("professor.password");
    MarksManagementRemote marksManagementRemote = EjbLocator.getLocator().getMarksManagementManager();
    Professor professor = marksManagementRemote.connexionVerification(login, pwd);
    if(professor!= null) {
        String name = professor.getName();
        String firstName = professor.getFirstName();            
        request.setAttribute("professor.name", name);
        request.setAttribute("professor.firstName", firstName);         
        session.setAttribute("professor.email", login);
        session.setAttribute("professor.name", name);
        session.setAttribute("professor.firstName", firstName);         
        getServletContext().getRequestDispatcher("/studentList.jsp").forward(request, response);
    } else {
        String message = "Invalid";
        request.setAttribute("message", message);
        getServletContext().getRequestDispatcher("/login_pro.jsp").forward(request, response);
    }
}

connexionVerification в MarksManagementManager:

@Override
public Professor verifConnexion(String email, String password) {
    Query query = em.createQuery("SELECT pt FROM professorpt WHERE pt.email= :email AND pt.password= :password");
    query.setParameter("email", email);
    query.setParameter("password", password);
    Professor professor = (Professor) query.getSingleResult();
    if(professor == null) {
        return professor;
    } else {
        return professor;
    }
}

И есть моя ошибка: (строка 35 файла LoginServlet такая: Professor professor = marksManagementRemote.connexionVerification(login, pwd);

enter image description here

Сердечно

...