File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet

 
vidya archana
Ranch Hand
Posts: 36
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 60
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.


------
Atul
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic