• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

RequestDispatcher does not update URL in Address Bar

 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am fowarding the user from a servlet to a JSP page using
getServletContext().getRequestDispatcher(refURL).forward(request, response);
and when I do this, the URL in the address bar still shows the Servlet URL and not the JSP url. I know the foward is working correctly, but I just don't know why the URL isn't updating in the address bar.
Thanks.
 
Sheriff
Posts: 67747
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
That's the intended behavior. When you forward the request using the dispatcher (a completely server-side operation), you are remaining within the context of the same request which was initiated by the URL seen in the address bar. The browser has no knowledge that you are forwarding things around on the server, and so the address remains unchanged.
This is quite different from a redirect which asks the browser to initiate the new request. In this case, the browser is completely aware of what is going on and updates the address field accordingly.
hth,
bear
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So I should be doing a response.sendRedirect() instead, right? Because I don't care about the request,response at this point. I just need to get back to the referring page.
[ September 18, 2003: Message edited by: Gregg Bolinger ]
 
Bear Bibeault
Sheriff
Posts: 67747
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
Right, if you want your JSP to display in a different request than the servlet, use a redirect. If you want the JSP to execute in the same request (done very often in Model 2 since the servlet does the processing and sets data on the request for the JSP to display), use a forward.
hth,
bear
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Great, I got it. Thanks Bear.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic