This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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 ]
Joined: Oct 11, 2001
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