• 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

How does a servlet know when it is being redirected to the right page

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am writing a servlet that will send certain parameters to a foreign servlet which will decide on which web page to display basing on the parameters sent. And my web application will process accordingly depending on which web page is sent. My problem is that how will my servlet know which web page it is being redirected. Is there any way I can know the URL of the web page that I am being redirected to?

Thank you

Vivian
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why not ask in our Servlets forum? Here, I'll move this there for you.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How is your servlet communicating with the foreign one ... URL or HttpURLConnection or something like that? Look in the doc or on Google for a "follow forward" option that makes one of those (forget which) automatically follow any forward headers sent back by the foreign servlet. I've set this to true before (maybe the default) but never really tested how well it works.
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
redirect is a clientside action therefore the HTTP response will contain the redirect URL as well as a return code in the 300 range indicating you're being redirected.

If the request is forwarded otoh you will notice nothing and you shouldn't bother as forward is purely serverside and completely transparent to the client (all the client notices is that the actual data in the response are different for different requests).
 
Vivian Ryder
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply, but how do I retrieve the URL contained in the HTTPResponse? Is the method losted in javadoc?

Thank you
reply
    Bookmark Topic Watch Topic
  • New Topic