• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1303
  • Last Modified:

JSTL session attribute problem

In my first JSP page (page1.jsp) I have:

<c:set var="message" value="Some message" scope="session" />
<c:redirect url="/page2.jsp" />

In the next JSP page (page2.jsp), I have:

<c:set var="message" value="${sessionContext.message}" />
<c:out value="Message=>${message}" />

Problem: Nothing displays. The session attribute 'message' is empty. I verified this with:

<c:if test="${empty message}" >
   <c:out value="session attribute is empty" />
</c:if>

Any ideas?

0
softechnics
Asked:
softechnics
  • 3
  • 2
1 Solution
 
rrzCommented:
><c:set var="message" value="${sessionContext.message}" />  
remove that line  
0
 
rrzCommented:
In fact if you  are using current versions of server, then   just try  
${message}
in page2.jsp
0
 
softechnicsAuthor Commented:
It works!

Why?!?!?!

The JSTL documentation I have explicitly shows ${sessionContext.varName} as the syntax for obtaining session attributes.

What do I not understand?
0
 
rrzCommented:
> ${sessionContext.varName}  
That is not right. It should be
 ${sessionScope.varName} or in this case
${sessionScope.message}  
or just  
${message}
because JSTL will search all the scopes to find it.
0
 
softechnicsAuthor Commented:
Thanks for the correction. I prefer to be explicit, just in case there's another local variable or request parameter by the same name. So, I'm using ${sessionScope.message}.
0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now