This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

RequestDispatcher display the servlet URL, not the jsp  RSS feed

 
peter tong
Ranch Hand
Posts: 250
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if using RequestDispatcher from a servlet and forward to a jsp, the user will see the servlet URL in the IE address bar, not the jsp URL, how to overcome this?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65830
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't. And why would you even want to?

The forward happens on the server and the browser has no idea that it has occurred. Nor should it.
 
peter tong
Ranch Hand
Posts: 250
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just think it is quite strange when a user is seeing a jsp page but the browser address bar is showing the servlet URL.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65830
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why would the user even know that they are looking at a JSP page? You can use servlet mapping to pretty much make URLs look like whatever you want, but users really needn't be concerned with what the URL is except to enter the web app initially.
 
omkar patkar
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi peter
if you are forwarding using the request dispatcher, that means, the transfer of control from the servlet to the jsp is taking place on the server side. The client...i mean ....the browser will not come to know about this forward. And exactly for this reason, the ...the response committed by the jsp is rendered at the browser end but the url belongs to the calling servlet.

And as mentioned earlier in this thread, by Bear, in an application, the user wouldn't be worried about, the response rendered and the url in the address bar.

However, if you want the user to know that the control was transferred from the servlet to jsp, then user response.sendRedirect() method. Due to this, the serlet will send a temporary HTTP code, with the jsp url you have provided, back to the browser, the browser understands the code, that the call needs to be made for some other resource, in such a case, the browser sends another request to the new url it recieved....and that is the reason why now, the response from jsp will be rendered at browser end PLUS, the url changes in the browser's address bar.

But its upto you which method to use. Go through FAQ of javaranch, and you will get more information on this.

hope this thing helps you
Zomkar
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!