Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Use variable session attribute names?

Reply
Thread Tools

Use variable session attribute names?

 
 
Kai Grossjohann
Guest
Posts: n/a
 
      12-11-2003
I have Foo.jsp that I want to call like this:

Foo.jsp?data=bla

And then Foo.jsp should do like

<jsp:useBean id="bla" scope="session" type=.../>

The "obvious" idea was

<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<jsp:useBean id="${param.data}" scope="session" type=.../>

Is there a way to get the behavior I'd like?

Kai
 
Reply With Quote
 
 
 
 
Tor Iver Wilhelmsen
Guest
Posts: n/a
 
      12-11-2003
Kai Grossjohann <(E-Mail Removed)> writes:

> Is there a way to get the behavior I'd like?


No, because useBean's id is compiled into a method variable name in
the resulting servlet source.

The best way of doing what you want would probably be a HashMap where
you use get() and put() with the passed parameter value as a key.
 
Reply With Quote
 
 
 
 
Kai Grossjohann
Guest
Posts: n/a
 
      12-12-2003
Tor Iver Wilhelmsen <(E-Mail Removed)> writes:

> Kai Grossjohann <(E-Mail Removed)> writes:
>
>> Is there a way to get the behavior I'd like?

>
> No, because useBean's id is compiled into a method variable name in
> the resulting servlet source.
>
> The best way of doing what you want would probably be a HashMap where
> you use get() and put() with the passed parameter value as a key.


What I've now done is to link certain session and page scope
attributes. People write:

<kai:link session="data" page="foo"/>

Internally, it does like this:

String sa_name = request.getParameter("data");
pageContext.setAttribute("foo", session.getAttribute(sa_name));

(The real implementation reads "data" and "foo" from the args of the
custom tag, instead of including them literally in the code.)

What do you think?

Kai
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
System Session Variable VS. Own-declared 'Session' Variable chowchho ASP .Net 7 03-28-2008 02:38 PM
Use of XSL:variable in XML-Attribute schaf XML 3 09-16-2005 08:22 AM
Can <jsp:useBean> use an EL variable in id attribute? Lee Francis Wilhelmsen Java 0 09-03-2004 05:52 PM
How to use xsl variable in attribute value? Richard XML 2 08-28-2004 09:47 AM
Datalist - how (if) to use a sub variable or session variable in the footer? KathyB ASP .Net 1 07-17-2003 01:35 AM



Advertisments