I am a JSP newbie. I am trying to create a JSP page for a new user profile creation. After the user enters all the required personal data he/she has to choose an user id and password. When the user hits the submit button the page calls an existing bean to verify if the user id already exists in the database. If the id already exists it will display a message on the page saying 'User already exists ...' and will blank both the user id and password fields. But rest of the other the user's data should remain visible. I have been somewhat able to display the message if the user id already exists on a new page. But the other input data is getting lost. Is it possible to stay on the same page and do this sort of user id validation? Wondering what is the best way to do this overall? Any hint with code snippet would help me greatly.
Using a traditional method, in other words submitting the whole page, you can restore the original values in the fields by using their value attributes and setting them to the submitted values.
Just one thought. As I have 8/10 fields for the personal data input. Should I have a hidden field for each of these and copy the input data in these hidden fields? Then later when the same page is refreshed then get these data back into the actual field? It would be helpful to know how I can copy data into hidden fields and re-populate back the actual fields with the same data. Is this one way of doing what I want to do?
Joined: Nov 03, 2003
Thanks for your really prompt response. Is there a code snippet I can use for what you are suggesting? It surely would help a newbie like me?
Originally posted by Tariq Ahsan: Is there a code snippet I can use for what you are suggesting?
For the traditional route, something like:
The EL expression in the value attribute captures the submitted value and makes it the initial value of the field. If the parameter doesn't exist, it will be blank so everything's cool first time around.
Joined: Nov 03, 2003
Can't thank you enough!. I'll try out what you suggested. Yes, I think I will have to do things in the traditional way.