Use variable session attribute names?

K

Kai Grossjohann

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
 
T

Tor Iver Wilhelmsen

Kai Grossjohann said:
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.
 
K

Kai Grossjohann

Tor Iver Wilhelmsen said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top