I used the following code to redirect to a jsp page from a servlet " RequestDispatcher disp; disp = getServletContext( ).getRequestDispatcher("searchresults.jsp"); request.setAttribute("my.search.results", searchResultsList); disp.forward(request, response);" I got the request session by this from the jsp page.But the url is showing the servlet path.So while reloading the page i get a script warning of the page submitting once more .So i used the response.sendRedirect();But i did get the request session . please help me
Joined: Dec 17, 2002
There is a huge difference in using response.sendRedirect() and dispatcher.forward().If u r using response.sendRedirect() u would be getting a fresh request object in the next page but you would have the same session, because in this case the server sends an HTTP 302 message back to the client telling it that the resource has moved to another URL and that the client should access it there. The bottom line is that the lifecycle of the initial request object that was accessed in the first JSP terminates with the end of the service method in the first JSP, or with the reply from the server.
While in case of dispatcher.forward(request,response) the same request object is being to the next page.This forwarding takes place at the server.