Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>First, you'd normally use <a href="http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JSPIntro7.html" rel="nofollow noreferrer">EL (Expression Language)</a> to display it:</p> <pre><code>&lt;p&gt;${message}&lt;/p&gt; </code></pre> <p>Second, the request attribute may be null in the view if you're actually doing a <strong>redirect</strong> to the view using <code>response.sendRedirect("/login.jsp")</code>. Even though the code displays you're doing a <em>forward</em>, but you told that you were redirecting to the login page. A redirect basically instructs the client to create a new request and hereby the original request including all of its attributes will be garbaged.</p> <p><strong>See also:</strong></p> <ul> <li><a href="http://courses.coreservlets.com/Course-Materials/csajsp2.html" rel="nofollow noreferrer">Beginning and intermediate JSP/Servlet tutorials</a></li> <li><a href="https://stackoverflow.com/questions/2349633/servlets-doget-and-dopost/2349741#2349741">More extended answer on the subject (also as asked in your previous question)</a></li> <li><a href="https://stackoverflow.com/questions/1945377/authenticating-the-username-password-by-using-filters-in-java-contacting-with-d/1946121#1946121">Authenticating a logged in user using Filters</a></li> </ul> <hr> <p><strong>Update</strong> as per your update, the <code>/login/index.jsp</code> is in turn apparently doing a redirect. I'd suggest to get rid of it and just have a <code>/login.jsp</code>. You can eventually hide it in <code>/WEB-INF/login.jsp</code> so that you can keep using nice URL's. Rewrite <code>LoginServlet</code> (of which I assume that it's listening on an <code>url-pattern</code> of <code>/login</code>) as follows:</p> <pre><code>protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.getRequestDispatcher("/WEB-INF/login.jsp").forward(request, response); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String username = request.getParameter("username"); String password = request.getParameter("password"); User user = userDAO.find(username, password); if (user != null) { request.getSession().setAttribute("user", user); response.sendRedirect("home"); } else { request.setAttribute("message", "Unknown user, please try again"); request.getRequestDispatcher("/WEB-INF/login.jsp").forward(request, response); } } </code></pre> <p>Also see the 2nd link which I posted in the <em>See also</em> list here above.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload