• 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

Combine Redirect and Forward

 
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there an HTTP header or other mechanism to force the browser to change the URL shown in the address bar (not redirect to a new URL to be loaded)? For example, you click a link with the URL "http://server/servlet?id=10&op=load", the servlet runs, and when it returns it tells the browser to display "http://server/servlet" as the URL for the page?

It's like client-side redirect since it changes the URL, but it's like server-side redirect (forward) in that it doesn't tell the browser to actually load another URL.

Here's the background:

I have a fairly simple servlet that displays a status screen with operation links when no parameters received. The operation links hit the same servlet, this time with parameters, that tell it what to do. I kept it all as one servlet since it's pretty simple.

Now, when an operation is performed, the work is done and the updated status screen is displayed. However, I want the URL in the browser to be the no-parameter status screen URL so they don't inadvertantly reload the page and perform the operation again. I used a client-side redirect to do this, and it works great.

However, now I'd like to display an error message on the status screen if the operation fails. Since it redirects to the status screen, the message must be stored in the session or elsewhere to save it. I can do this, but it seems far more work than is needed.

Does anyone know a simple solution like I outlined at the start? Thanks!
 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Sorry to ask but, did you tried to use POST instead of GET to remove your parameters and then, empty your doGet function in your servlet to make sure it will not be reprocess again?

Quite simple but had to ask...

 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, I haven't tried that. I'm more a backend guy, so forgive my ignorance on this. I assume that to use POST with plain links (anchor tags) I'd have to use JavaScript to set some hidden form fields and submit the form; is that correct?

Upon thinking about it a little more, it seems that using the HTTP session might work pretty well.

In fact, I suspect that I can't do as I originally hoped as it's probably a security risk to allow a web server to set the URL for the loaded page since the user will think that the browser actually loaded the page at the new URL, yet it didn't.
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
using HTTP forward calls is completely transparent to the client, he never knows it happens.
There's no security risk as you can only forward to a relative URI (so one within the same domain). If your customers consider that a security risk, fire them and find other customers
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic