jQuery in Action, 3rd edition
The moose likes Servlets and the fly likes Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet " Watch "Servlet " New topic


vidya archana
Ranch Hand

Joined: Oct 29, 2002
Posts: 36
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
Atul Prabhu
Ranch Hand

Joined: Dec 17, 2002
Posts: 60
hi Vidya,

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.

Hope this helps.

I agree. Here's the link: http://aspose.com/file-tools
subject: Servlet
It's not a secret anymore!