Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

data persistence across many JSP's

 
kiran giriya
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello
i m having 5 jsp's ,each jsp containing some 10 to 15 form fields.I need to have the data entered by the user in each Jsp's to be available in all other jsp's and so that in my final jsp i should have all the form values of 5 jsp's.One way it can be done is passing as hidden parameters to all jsp's and fetching by request.getParameter or using jsp:forward and param tags.But i feel this is cumbersome.What are the other all possible ways.Please let me know all the other way of doing.Thanks in advance.
regards
kiran
 
Shawn Bayern
Author
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by kiran giriya:
Hello
i m having 5 jsp's ,each jsp containing some 10 to 15 form fields.I need to have the data entered by the user in each Jsp's to be available in all other jsp's and so that in my final jsp i should have all the form values of 5 jsp's.One way it can be done is passing as hidden parameters to all jsp's and fetching by request.getParameter or using jsp:forward and param tags.But i feel this is cumbersome.What are the other all possible ways.Please let me know all the other way of doing.Thanks in advance.
regards
kiran

Typically, the easiest way to share data among JSP pages is to use the 'session' scope (corresponding to an HttpSession object). If you use scriptlets, you can write

to set information and

With JSTL (the JSP Standard Tag Library), you can write

and retrieve info from the session using expressions like
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
kiran
If you've got that many fields to pass you might want to create an object to hold them (if it is applicable) and then use Shawn's suggestion of the Session and then you'd just have to pass one object not all of the fields. Of course you'll still have to set all of the values in the object.
That would be a perfect place for a bean just set up a bean with the same member names as the form fields and the you can use the setProperties tag to set them all at once. Then create a method in the bean to return one of those object to store in the session.
 
Andres Gonzalez
Ranch Hand
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys..
Well, I thought about using a bean, just as dave commented. but, what I'd do is in every JSP page I'd type

so I will have access to all information in every page... Is that OK??
correct me if I'm wrong.
thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64982
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just be aware that the useBean tag will create an instance of the bean using the default constructor if one hasn't already been created and set into the session with that name.
hth,
bear
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic