Keeping form input values

F

francan00

I am going to create a form that will have about 3 pages of inputs in
one form.
The first and second page will have continue button and the final page
(3rd page) will have the submit (into database) button.

What is the best way to forward the form inputs from each page so all
will be submitted?

I will use MVC architecture but dont have Struts on our Tomcat 4.1.27
container.
 
W

Wojtek

I am going to create a form that will have about 3 pages of inputs in
one form.
The first and second page will have continue button and the final page
(3rd page) will have the submit (into database) button.

What is the best way to forward the form inputs from each page so all
will be submitted?

Create an object which will hold all the form inputs, and store that
object in the user's session. You can also store state, so you know if
the user clicks on the Back button, or tries to go to page two without
first going to page one.
 
F

francan00

(e-mail address removed) wrote :



Create an object which will hold all the form inputs, and store that
object in the user's session. You can also store state, so you know if
the user clicks on the Back button, or tries to go to page two without
first going to page one.

Thanks, I assume I can create an object using JavaBean class where I
will take all the fields (via getter and setter methods) and use a
special method to grab all the fields into one object. Then call that
special method in my Servlet?
 
L

Lew

I assume I can create an object using JavaBean class where I
will take all the fields (via getter and setter methods) and use a
special method to grab all the fields into one object. Then call that
special method in my Servlet?

That's one way, although you don't really need any method more special than
doPost(), unless things get large enough to refactor.

You could also, for example, use the ServletRequest method getParameterMap()
and work directly off the Map of parameters:
<http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletRequest.html#getParameterMap()>

This has the advantage of grabbing all the parameters in one fell swoop, and
the disadvantage of leaving all the parameter values as unvalidated Strings
packaged in the String [] values of the Map.
 
W

Wojtek

fr-)[email protected] wrote :
Thanks, I assume I can create an object using JavaBean class where I
will take all the fields (via getter and setter methods) and use a
special method to grab all the fields into one object. Then call that
special method in my Servlet?

Well, you CAN use a bean, but a simple class will also do. Extracting
form fields from the request is not all that difficult, and it lets you
condition the information, for things like valid input, ie: all numbers
for a numeric value, and within bounds, so that month value is within
1 and 12 inclusive.

NEVER assume that the user is kind enough to always enter valid values
:)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top