File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes dynamically send user back Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "dynamically send user back" Watch "dynamically send user back" New topic

dynamically send user back

gaurav chaudhary
Ranch Hand

Joined: Jun 24, 2002
Posts: 64
I have made one html which takes data to a servlet which finally inserts it into database. But if any error occurs in the servlet(flow goes within the catch statement), then browser should automatically go back one page to html where form is there with all values entered in the form(same function which we do by pressing browser's back button.).

Thomas Goorden
Ranch Hand

Joined: Aug 15, 2001
Posts: 39
I'm assuming you get exceptions when a user enters incorrect information (text where you expect an integer perhaps?).
The proper thing to do is to catch the exception and use the information the user supplied to build a new page with some extra information in it.
If you really want to redirect a user (the user will lose the information he/she has entered!), it might be possible to get the "referrer" from the HTTP request header and do a response.sendRedirect on that. However, this will probably just send them back to an empty form without any information on what happened. (plus, you don't always get a referrer from the browser)
Hope this helps,
I agree. Here's the link:
subject: dynamically send user back
It's not a secret anymore!