Use variable session attribute names?

Discussion in 'Java' started by Kai Grossjohann, Dec 11, 2003.

  1. 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
    Kai Grossjohann, Dec 11, 2003
    #1
    1. Advertising

  2. Kai Grossjohann <> 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.
    Tor Iver Wilhelmsen, Dec 11, 2003
    #2
    1. Advertising

  3. Tor Iver Wilhelmsen <> writes:

    > Kai Grossjohann <> 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
    Kai Grossjohann, Dec 12, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. KathyB
    Replies:
    1
    Views:
    422
  2. Carl
    Replies:
    0
    Views:
    514
  3. wanwan
    Replies:
    3
    Views:
    415
    Alex Martelli
    Oct 14, 2005
  4. chowchho
    Replies:
    7
    Views:
    617
    Patrice
    Mar 28, 2008
  5. News123
    Replies:
    2
    Views:
    457
    John Machin
    Nov 26, 2008
Loading...

Share This Page