• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Myu bethovan
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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.
 
Annie Smith
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are making use of one HttpSession, your attribute names should be different.
 
Chidanand Chauhan
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • 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.
 
Gaurav Chhabras
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • 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");
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • 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.
 
narayana arya
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • 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>
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!