Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

request.sendRedirect or javascript: document.location.replace()  RSS feed

 
verduka fox
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We are developing JSP projects on WAS3.5. We are not using J2EE or XML. We are currently using all JSP's in our projects without the use of servlets. When we need to redirect to a different page, we use:
<script language="JavaScript1.2">
<!-- Begin
top.document.location.replace('LoginAgain.jsp');
// End -->
</script>
We have begun looking into using servlets instead of this approach. What is the difference in using the above technique and using sendRedirect? In a previous post from 5/17/2002, markkid explains that sendRedirect uses the following approach: server->browser->server->browser. Is this more efficient than the document.location.replace described above?
Would you recommend continuing in our current approach or switching to use servlets? Please explain.
One more thing: we are reluctant to use the RequestDispatcher.forward() tag because it leaves the servlet name in the URL in the address bar (ie http://host/projectname/servlet instead of http://host/projectname/file.jsp). If there's a way around this, please let us know.
Thanks in advance.
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sendRedirect is more effiecient than the JavaScript exmple. The JavaScript example requires that the entire page load before the redirect occurs. sendRedirect only returns an http header code for Redirect. The initially requested page never loads in the browser.
sendRedirect is a method in HttpServletResponse which you have available in a JSP page. As long as you follow the rules and do nothing previous to this to cause any part of a response to be sent to the client, you can use it there.

sendRedirect accepts either Absolute or Relative URL's just ensure it is formatted correctly.
[ May 20, 2002: Message edited by: Carl Trusiak ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!