tomcat-taglibs-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Shawn Bayern <bay...@essentially.net>
Subject Re: Is a way to access/retrieve an attribute in the session scope using JSTL
Date Wed, 07 Aug 2002 05:27:00 GMT
On Tue, 6 Aug 2002, Vernon Wu wrote:

> Hi, Shawn,
> 
> I guess that I was tired and didn't read the chapter carefully.
> 
> The tag I need is 
> 
> <c:set value="${...}" target="${helper}" property="hostID"/>
> 
> where the 'value' is request.getSession().getAttribute(WebKeys.UserID)
> 
> and the 'WebKeys' is an interface containing keys to store data. Its code fragment is:
> 
> public interface WebKeys {
>     public static final String UserID = "com.vernonwu.mm.UserID";
> 	// ...
> }

The expression language doesn't read public fields of variables, and it
isn't meant to be used against static properties of classes either.  It's
primarily intended as a bean-oriented expression language with some
extensions for standard J2SE collections.  So you'll need to factor down
the expression a bit more.

Retrieving a variable from the session scope is easy; just say
${sessionScope.variableName}.  As for variableName, I'd set this as a
scoped variable in your page (based on the value of WebKeys.UserID) before
calling it.  That is, in a servlet, you could write

  request.getSession().setAttribute("userId", WebKeys.UserID);

Then, you could write

 ${sessionScope[userId]}

> Based on your suggestions, I have tried various expressions without a
> luck. I guess the problem is either the interface, or the static
> string type.

Yeah, it's with both.  :-)

-- 
Shawn Bayern
"JSTL in Action"   http://www.jstlbook.com


--
To unsubscribe, e-mail:   <mailto:taglibs-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:taglibs-user-help@jakarta.apache.org>


Mime
View raw message