Link to home
Start Free TrialLog in
Avatar of jwright9
jwright9

asked on

Is it possible to set a session attribute in a JSP and then recall it when the page is loader at a later time?

Is it possible to set a session attribute in a JSP and then recall it when the page is loader at a later time?
My attribute is actually set below where it is gotten.  Its okay if the first load of the page is null but when the page is returned to in a minute or so, I would like to get the value when I reload the page.  Here is are the lines of code as they appear in my JSP:

My flag value is <%=  session.getAttribute("relatedCasesFlag")%>

<% session.setAttribute("myVisitFlag", Boolean.valueOf(true)); %>
Avatar of rrz
rrz
Flag of United States of America image

Yes, a session-scoped object will be around for the whole session.  
Please restate your question. It is not clear.
Avatar of jwright9
jwright9

ASKER

Sure I'll be glad to restate it.   I want to set a flag when a user first visits a page.  The flag is set to true and I put the value of myVisitFlag to true.

<% session.setAttribute("myVisitFlag", Boolean.valueOf(true)); %>

When the user visits the page again, the flag will be set to true.  In my page's JSP code, I have put the line you see below above the line where the value is put in the session.

My flag value is <%=  session.getAttribute("relatedCasesFlag")%>  

If the flag is true the page has been visited before and my other code behaves how I need it to when the page has been visited already.  Hope this helps.  Thanks for your help.

I am still unclear as to what you are trying to do here.  You don't need to create a flag in order to know if the user has joined the session and has returned to the page. See code below here.
<html>
<body>
<%
  if(session.isNew()){
                      out.print("This is your first visit for this session.");
  }else out.print("This is a repeat visit for this session.");
%>
</body>
</html>

Open in new window

I insert this code in my page but it did not work.  It definitely should work I would think.  I am working inside of RAD 7.  I ran the application in a separate browser and it still did not work.
Oh one other thing.  I not concerned if the session is new or not.   I want a flag so that when the user goes up in the page "hierarchy" I can reset the flag so that things are reset back to normal until the user visits the page again and drills down into links on the page.
ASKER CERTIFIED SOLUTION
Avatar of rrz
rrz
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This helped thanks rrz@871311.  There was a process that was clearing out the "unregistered" name value pairs from the session.  I really appreciate the effort that you put forth and the example code helped me understand the situation much better.  Cheers.
This person is a great teacher.