File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes using one bean across several forms Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "using one bean across several forms" Watch "using one bean across several forms" New topic
Author

using one bean across several forms

dibs dibley
Greenhorn

Joined: Aug 31, 2003
Posts: 13
Hi,
In my application the user chooses an 'id' from a list (choice.jsp) and then is brought to a number of html forms (6 jsp files in total) where they fill out different information in each of the forms.
Each form must be populated by information from the database, and each time a change is made to a form that change must be recorded in the database.
The primary key is the 'id' so i must pass this to each of the forms so as they can get the correct record information for that 'id'.
I was going to use an id-bean with session scope for the 'id' and indivdual beans with request scope for each of the forms.
When the user goes from choice.jsp to the first form they will be first brought to a servlet which will set the 'id' attribute in the id-bean and retrieve all the database fields for that form and put the info in that form's bean, each of the form.jsp's will have their own servlet that will get the fields from the database.
Will this type of approach work, and as well sometimes i may want to add a new user , so their will be no 'id' field at the start, how do i make sure the 'id' of the last user is not still held in the id-form so no information will be retrieved from the database?
Thanks in advance
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
Putting the key into the session is indeed the best way.
Do NOT put the database Connection or the ResultSet into the session as that can have disastrous results!


42
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: using one bean across several forms