• 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 ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

How to restore form Data in Java

Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am working with a registration form.
Currently when I press submit button and if any input is wrong , I am redirected to same page with all the previously filled fields blank. I want that my previously filled value persist.

Can any one help me out , how to achieve this is Java. I am using Java, .page file and xsl for rendering things. I can't use PHP for this.
Either I can do this on my xsl file or on Java script.

Please help. I do urgently need this.

Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want to store form data you typically put it into a data object in the session (after submitting). If you go back to your output page, you access that object and put the values in there into the form fields. Best do a search in the jsp and servlet forums here on this site, this question probably comes up frequently.
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If this is just a single jsp page form (i.e the form itself doesn't span multiple pages) you don't need to use the session.

Maybe this MVC example will help? This is just a basic example. There are many different methods to do the same thing.

(M) = Model
(V) = View
(C) = Controller

First Part
1) User directs browser to RegistrationFormController (C) url
2) LoginFormController is a servlet that creates an empty RegistrationForm bean and puts it on the request object, named "regDetails". The bean has methods such as setFirstName(String name) and getFirstName().
3) LoginFormController forwards (dispatches) the request to registrationForm.jsp (V)
4) registrationForm.jsp uses JSTL to put values from bean (empty at the moment) in to the form values.

Second Part
1) User fills in form and clicks submit button. This posts the data to the RegistrationController (C)
2) RegistrationController takes the submitted values from the request object and creates a RegistrationForm bean using these values.
3) RegistrationController then validates the bean values to make sure they are of the correct data types, all mandatory fields have values etc.
4) If no problems, calls some business logic (M) to do whatever you need to do with the data (save it to a database maybe?) - Note - this could also provide validation errors for example if the username already exists in the database etc.
5) If problems, forward to success.jsp to display a success message.
6) If problems, put bean back in response object. Add error message to response object. Forward to registrationForm.jsp again.

That should at least get you started...

Your buns are mine! But you can have this tiny ad:
the value of filler advertising in 2021
    Bookmark Topic Watch Topic
  • New Topic