Отображение сообщения об ошибке входа в систему в JSP - PullRequest
0 голосов
/ 03 июня 2018

Я пытаюсь отобразить сообщение об ошибке на своей странице index.jsp, если пользователь вводит неверный логин.

Вот мой код сервлета:

if( passwordService.authenticate(password, attemptedPassword, salt)){


        User user = LogicFacade.login(email, password);

        HttpSession session = request.getSession();
        session.setAttribute("user", user);
        session.setAttribute("role", user.getRole());

        return user.getRole() + "page";  // i return the name of the jsp page, to get to the next jsp page

    }else{

    //here I make the error message I want to show
        String errorMessage ="The retrived password or username did not match";
        request.setAttribute("errorMessage", errorMessage );
           RequestDispatcher rd = request.getRequestDispatcher("/index.jsp");
                rd.forward(request, response);  
    }

}       catch (SQLException | NoSuchAlgorithmException | InvalidKeySpecException | ServletException | IOException ex) {
        Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;

}
}

Здесь я отображаю его в моем jsp:

 <%
if(null!=request.getAttribute("errorMessage"))
{
    out.println(request.getAttribute("errorMessage"));
    out.println("<p> Error!! </p>");
    //ved godt det ikke er super smart at printe paragraph tags med ud
}

 %>

Почему сообщение не отображается?

1 Ответ

0 голосов
/ 04 июня 2018

попробуйте это может решить вашу проблему

   if(!request.getAttribute("hello").equals(null))
...