0 Replies Latest reply on Feb 3, 2006 4:44 PM by mandelbr0t

    Request attributes not working as expected

    mandelbr0t

      Hi,

      I have a simple change password form that works something like this:

      (in home/changePassword.jsp)
      <%
      RequestDispatcher rd = request.getRequestDispatcher("/servlet/AuthenticatedUser");
      rd.include(request, response); // sets the 'user' request attribute
      User user = (User) request.getAttribute("user"); // User is defined somewhere else
      %>
      ...
      <h2>Hello, <%= user.getName() %></h2>
      ...

      ...


      (in ChangePassword.java)

      protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
      // process request
      // if (ok) change password
      RequestDispatcher rd = req.getRequestDispatcher("/home/changePassword.jsp");
      rd.forward(req, resp);
      }

      The problem is that the variable user is null after POSTing to this servlet. Why does the request attribute get set correctly when I GET /home/changePassword.jsp, but not when I use RequestDispatcher.forward() from the ChangePassword servlet?

      Thanks,
      mandelbr0t