Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SendRedirect doubt

 
Vani Chinta
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I am trying to direct a request "http://localhost:8080/ch4/dog.do" to some other jsp.

1) Does the new JSP path appear in Address bar of the IE page? I donot see the new jsp page in the address bar rather title of the IE has changed to reflect new jsp.

2) In the redirecting servlet I gave SOP statement which is not printed on to the console. Where am I going wrong? However the request is being redirected to the new jsp.


Here is the servlet code for reference.

package com.example.web;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class RedirectServlet extends HttpServlet{


public void doGet(HttpServletRequest request,HttpServletResponse response)
throws IOException,ServletException{


System.out.println("Inside redirecting servlet");
response.sendRedirect("/redirected.jsp");

}

}
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) Does the new JSP path appear in Address bar of the IE page?
Nope

2) In the redirecting servlet I gave SOP statement which is not printed on to the console. Where am I going wrong? However the request is being redirected to the new jsp.
If you are refreshing the screen, the browser may be caching the redirected.jsp and returning the cached version without sending another request to the server. You can approach this in a few different ways. The quickest and dirtiest is to add a bogus request parameter to your URL to make the URL unique. Basically, add something like ?blah=blah to the end (and change the value whenever you want a new unique URL).
 
Vani Chinta
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Marc for the clarification. Looks like it is caching the page. I passed parameters and it is working fine.
 
Vani Chinta
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Page 139 of HFSJ, it is mentioned that new URL appears on the address bar.
Should that be mentioned in Errata?
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vani,

In case of request redirect, user sees changed URL in the address bar whereas
in the case of request dispatch, user does not see changes in the address
bar;

Request dispatch means delegating the request to any other jsp or servlet in
the same web application, so abstraction is maintained, hiding the URL from
the browser which actually processed the user request.



Thanks,
[ July 18, 2007: Message edited by: Chandra Bhatt ]
 
Deepa Jaine
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Chandra,

As per the code given in this post, the sendRedirect should then show the new URL in the address bar, am I right?
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As per the code given in this post, the sendRedirect should then show the new URL in the address bar, am I right?


I agree!


Thanks,
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic