• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

RequestDispatcher display the servlet URL, not the jsp

 
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 333
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic