Using RequestDispatcher to forward to the same page that send request
I have a servlet, which is called "LoginServlet", an index.jsp, which has the login form (username & password). I send the request to the LoginServlet, and used:
getServletContext().getRequestDispatcher("/index.jsp").forward(request, response);
To go back to th开发者_运维百科e index.jsp with the username and user information (To display Welcome XXX on top right of the screen). The problem is, I cannot use ${requestScope.userName} to retrieve the username. The userName simply does not exist in the request. However, when I dispatched to another jsp page, it did receive the request with new information and I could retrieve it.
I want to know is there a way to forward to the same page which send the request? I simply cannot get the data dispatched from servlet to the same page, i.e. for making user logged in
精彩评论