• 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 ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

How to set the session attribute for the different jsp page data value.

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could anyone please tell me. Suppose i have an application which contains 10 different JSP pages. And each JSP page contains some data, which we have to store for the future use. Now after going through all the 10 pages i want some calcuation related to the last 10 data values which were picked from the different JSP pages.

So i suppose i use HttpSession for this but how to maintain all these data values. Means i use one HttpSession object among all JSP pages but how would i place the values in the HttpSession object, i suppose through setAttribute. But, should i use different attribute for the different jsp or only one attribute for different Jsp.

please tell me.
 
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are making use of one HttpSession, your attribute names should be different.
 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Annie Smith:
If you are making use of one HttpSession, your attribute names should be different.



Hi Annie,

Could you please explain your above comment.
 
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you have to use -:

getServletContext().setAttribute("some String value",value);

and at receiving time -:

String abc = (String)getServletContext().setAttribute("that String value which you give above");
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You might consider making one bean that contains a stack (or similar object).
As the user picks from his/her choices, add that choice to the stack.

Then give it a getResults method which tallys up the results and returns something the JSP can use for display.

Bind this object to session with the setAttribute method.
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if you use session then give different names
like session.setAttribute("one","1")
session.setAttribute("two","2")
session.setAttribute("3","3")

OR ELSE

store use beans.
ang dive that beans scope as session.

for example.
give like this in 10th jsp page.
<jsp:usebean id="data" class="...." scope ="session">
<jsp:setProperty name="data" property = "*">
</jsp:useBean>
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic