This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Redisplay Variables in JSP after Failed Validation?

 
David Ogasawara
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Kj Reddy
Ranch Hand
Posts: 1704
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
David Ogasawara
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
David Ogasawara
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So that's how you do it!!!

THANK YOU!!!

I'm going to print the page and nail it to my wall.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic