This week's book giveaway is in the Design and Architecture forum.
We're giving away four copies of Communication Patterns: A Guide for Developers and Architects and have Jacqui Read on-line!
See this thread for details.
  • 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

error page forward

 
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have several forms, each has its validation logics for inputs, suppose in one of the middle forms there is anything wrong in the input, I want to direct user to an error page, but I don't want them to lose what they have done up to that point === in other words on the error page I want them to click browser's back button and go back to the last form which o they paused.

In this case, will a "forward" work for me ?
 
Sheriff
Posts: 67750
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
The browsers back button doesn't give you any opportunity to run code at all.
 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

in other words on the error page I want them to click browser's back button and go back to the last form which o they paused.



I don't think this works, because when you click on the browsers back button the form will be reset and so you will see all the values blank.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A better an more typical way to handle this is to return the user to the form that they've just submitted (with the form still filled out).
Have that page display an error message letting them know which fields have problems. This way they don't have to click the back button to the to the form and they'll have the error message on the same page as the form fields.
 
ben oliver
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I guess I didn't express it clearly. It is OK for me to have all fields appear blank. What I want is --- Suppose I am on the third form (each fomr is a separate page) and there is some error, I want it to direct to a standard error page, and on the error page, when I click BACK button, I want come back to the third page (it is fine to show me a blank third form). Does "forward" work for this ?

I appreciate there is better way to handle the error, but still want to get the answer to above question.

Thanks.
 
Bear Bibeault
Sheriff
Posts: 67750
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
Again, when the back button is clicked, you have no opportunity to run any code, so asking what code to use is pointless.

Rather, let's back up a bit and examine what you are doing. Sending the user to a separate error page is not only poor UI, it adds levels of complexity that you are stumbling over. Why not do something thats better UI, more conventional, and easier to control?

Rather than sending them to another page when you detect an error with the form data, most web apps will send the user back to the same form page with the error message embedded on the page itself. This is not only more user-friendly, but eliminates any nonsense with the back button.
 
Prasad Tamirisa
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rather than sending them to another page when you detect an error with the form data, most web apps will send the user back to the same form page with the error message embedded on the page itself. This is not only more user-friendly, but eliminates any nonsense with the back button.



This how we generally do in the real time situation.
[ May 27, 2008: Message edited by: Prasad Tamirisa ]
 
ben oliver
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Prasad Tamirisa:


I don't think this works, because when you click on the browsers back button the form will be reset and so you will see all the values blank.



Now I understand the back button does not work. But in servlet/JSP, once it is forwarded to the error page, is there a way for user to go back to the previous page that triggered the error without losing other info already saved in session (it is ok to view that page as blank) ? what api method can do that ? Again, I know there is better solution but just want to know if it is possible.
 
Bear Bibeault
Sheriff
Posts: 67750
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

Originally posted by ben oliver:
what api method can do that ?


If you are expecting a method that can magically remember data that that is no longer available, you will be disappointed. Failing to follow the earlier advice, you'll need to store the data away in the session and retrieve it later when you want to repopulate the page.
 
Prasad Tamirisa
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Best solution that i suggest in this case is,


When some thing goes wrong, redirect the user to the same page with the corresponding error message displayed above the text box.


You can do this using the struts error tags.
 
Bear Bibeault
Sheriff
Posts: 67750
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

Originally posted by Prasad Tamirisa:
You can do this using the struts error tags.

Please do not assume people posting in the JSP forum are using Struts.
 
ben oliver
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now gentlemen, when some error occurs, can I stay on the same page (redisplay the current form, suppose it is the 3rd form, stay on it and add error message, the fields can be blank though) instead of going to a separate error page ? If that's the case I guess I will not lose the data I entered in the first 2 forms, correct ?

What method shall I use in this kind forward ?

And Yes, please don't assume we are using struts.

Thanks.
 
Bear Bibeault
Sheriff
Posts: 67750
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
If you are collecting information from multiple forms, you're going to need to store it on the server or propagate from page to page using hidden elements. Most people would collect this information in the session and it will available to populate the various forms with the data.

And yes, not going to separate error page would be vastly preferred over showing the errors in-place.
 
Prasad Tamirisa
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bear Bibeault:
Please do not assume people posting in the JSP forum are using Struts.



Thanks Bear.

:thumb:
 
ben oliver
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bear Bibeault:
If you are collecting information from multiple forms, you're going to need to store it on the server or propagate from page to page using hidden elements. Most people would collect this information in the session and it will available to populate the various forms with the data.

And yes, not going to separate error page would be vastly preferred over showing the errors in-place.



Bear (your name is so close to another moderator who is also on these forum..), thanks for reminding me of the hidden field. What I am thinking is --

Suppose I am on the 3rd form, after I click submit button, if the server detects some error, let's say I want it to re-display the 3rd form to user and blank out all the fields he has entered (reset). Can I do something like

..getDispather(request.getRequestURL().toString()).forward(request, response)

But I guess at this point, since I have clicked submit, it invokes the next action, so request.getRequestURL() should return me with the NEXT URL, so it will NOT forward back to the current 3rd form. DO I understand it correctly ? If so, how should I code to let it forward "back" to current form ?

Plus, for hidden fields, suppose I have hidden fields carried from 1st form, will this forward loose the hidden field values ?

Thanks.
 
I don't always make ads but when I do they're tiny
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic