Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get sessionScope attributes on JSTL?

The task is to retrieve parameters from session via JSTL. The session parameter name is "programId" .

I tried:

 <c:if test="${sessionScope.programId != null}" > 
  please execute
  </c:if>

Then I tried:

 <c:if test="${sessionScope:programId != null}" > please execute </c:if>

Here I get: The function applicationScope:programId is undefined

On top I have:

 <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

Oracle has in examples:

http://docs.oracle.com/javaee/1.4/tutorial/doc/JSTL5.html

 <c:if test="${applicationScope:booklist == null}" > 
   <c:import url="${initParam.booksURL}" var="xml" />
   <x:parse doc="${xml}" var="booklist" scope="application" />
</c:if>  

where applicationScope can be swapped by sessionScope.

again "trivialism" complexity drives me nuts. Why corp. examples never work?

Thank You Guys,

like image 968
Aubergine Avatar asked Oct 09 '22 02:10

Aubergine


1 Answers

You're reading the wrong tutorial page. The <c:xxx> tags does not belong to the JSTL XML taglib which supports XPath syntax. Instead, it belongs to the JSTL Core taglib for which the proper tutorial page is here.

You need to use the normal ${bean.property} notation instead.

<c:if test="${applicationScope.booklist == null}"> 
   <c:import url="${initParam.booksURL}" var="xml" />
   <x:parse doc="${xml}" var="booklist" scope="application" />
</c:if>

In normal EL (not XPath!) syntax, the : identifies the start of an EL function. See also the JSTL Functions taglib for several EL function examples for which the tutorial page is here.

See also:

  • Our JSTL tag wiki page
  • Our EL tag wiki page
like image 186
BalusC Avatar answered Oct 18 '22 08:10

BalusC