Forums Register Login
Redisplay Variables in JSP after Failed Validation?
I have a jsp that contains a name (populated from database) and a blank email field. When the user presses the submit button, I validate the email and send it back to the jsp page if it fails.

How am I supposed to redisplay the name? I have been placing it into a session variable, but is that the only/best way? What if I have a lot of variables (name, address, phone, arrays)?

The entire app:
1. jsp -- User enters ID
2. action -- grab name from database based on ID and place in session variable
3. jsp -- display name and ask for email
4. action -- validate email
5. jsp -- display name (problem here), ask for email, display validation error
[ August 09, 2005: Message edited by: David Martin ]
Keeping the name in session is not better idea if it is just required to display back. If you want to have this variable thru out application in different pages you can keep it in session. Other wise just use HttpRequest method getAttribute() and setAttribute() to share the name.

If you have more than one variable then you can create a java bean classes with all properties of name, address, phone. And share that java bean between the pages.

Hope it helps you.
[ August 09, 2005: Message edited by: KJ Reddy ]
Thank you for the response! Unfortunately, using HttpRequest does not work. I can initially get it to display the name in the jsp, but after a failed validation, the redisplayed jsp is blank.

EmailAction: get name from database
email.jsp: display name, email field (form action="email")
EmailAction: validate emailAddress (failed) ---> mapping.findForward("failure")
XML: <forward name="failure" path="/email.jsp"/>
email.jsp: name not displayed, email field, error message

I will continue to experiment.
When you display (as in text-only) a variable like that, you need to also set it with a html:hidden tag to propogate across validation.
So that's how you do it!!!


I'm going to print the page and nail it to my wall.
Your mother was a hamster and your father was a tiny ad:
ScroogeXHTML 7.1 - RTF to HTML5 / XHTML converter

This thread has been viewed 1276 times.

All times above are in ranch (not your local) time.
The current ranch time is
Feb 19, 2018 20:39:21.