get static variable from class into JSP tag scope

Discussion in 'Java' started by Robert Mark Bram, Jan 22, 2008.

  1. Hi All,

    I have a static variable in a class that I wish to share with some of
    my JSP code. Can I use the <jsp:useBean> (or any tag?) to get that map
    into the scope of my JSP tags?

    Thanks for any assistance,

    Rob
    :)
     
    Robert Mark Bram, Jan 22, 2008
    #1
    1. Advertising

  2. Robert Mark Bram

    Lew Guest

    Robert Mark Bram wrote:
    > Hi All,
    >
    > I have a static variable in a class that I wish to share with some of
    > my JSP code. Can I use the <jsp:useBean> (or any tag?) to get that map
    > into the scope of my JSP tags?


    <jsp:useBean> requires that the bean be in scope, i.e., entered into the
    context of the page, request, session or application, e.g., via
    <http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletRequest.html#setAttribute(java.lang.String,%20java.lang.Object)>

    You can also use Expression Language (EL) to access such beans.

    You could also use scriptlet, but don't.

    You could also use Java Server Faces (JSF), which has a way to directly
    connect component attributes ('value', 'binding', 'action') to bean methods
    and attributes. There is a learning curve involved there.

    --
    Lew
     
    Lew, Jan 23, 2008
    #2
    1. Advertising

  3. Robert Mark Bram

    Hal Rosser Guest

    "Robert Mark Bram" <> wrote in message
    news:...
    > Hi All,
    >
    > I have a static variable in a class that I wish to share with some of
    > my JSP code. Can I use the <jsp:useBean> (or any tag?) to get that map
    > into the scope of my JSP tags?
    >
    > Thanks for any assistance,
    >
    > Rob
    > :)


    try
    <%@ page import = "yourpackage.YourClass" %>
     
    Hal Rosser, Jan 23, 2008
    #3
  4. Hal Rosser wrote:
    > "Robert Mark Bram" <> wrote in message
    > news:...
    >> Hi All,
    >>
    >> I have a static variable in a class that I wish to share with some of
    >> my JSP code. Can I use the <jsp:useBean> (or any tag?) to get that map
    >> into the scope of my JSP tags?
    >>
    >> Thanks for any assistance,
    >>
    >> Rob
    >> :)

    >
    > try
    > <%@ page import = "yourpackage.YourClass" %>
    >
    >
    >

    And after that:
    <%= YourClass.VALUE %>

    --
    Regards,
    Jonatan Kazmierczak
    SCJP SCJD TC_rated_member Linux_user
    Asm86 Bash C/C++ Java JavaScript Pascal Perl PHP Ruby TCL VB VBS XSLT
     
    Jonatan Kazmierczak, Jan 23, 2008
    #4
  5. Hi Hal,

    > try
    > <%@ page import = "yourpackage.YourClass" %>


    Sorry, I should have been more specific - I wanted to get the value
    into the scope of my jsp tags, not a scriptlet. Thank you for your
    response though. :)
     
    Robert Mark Bram, Jan 23, 2008
    #5
  6. Thank you Lew,

    > > I have a static variable in a class that I wish to share with some of
    > > my JSP code. Can I use the <jsp:useBean> (or any tag?) to get that map
    > > into the scope of my JSP tags?

    >
    > <jsp:useBean> requires that the bean be in scope, i.e., entered into the
    > context of the page, request, session or application, e.g., via
    > <http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletRequest.ht...)>


    This supports the MVC pattern quite strongly, so I am not as
    disgruntled as I was at first - now I see a reason for it. :)
     
    Robert Mark Bram, Jan 23, 2008
    #6
    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. jstack
    Replies:
    1
    Views:
    613
    Tor Iver Wilhelmsen
    Jul 4, 2003
  2. Sean Aitken
    Replies:
    3
    Views:
    11,056
    Alex Hunsley
    Oct 21, 2004
  3. Paul Opal
    Replies:
    12
    Views:
    961
    Paul Opal
    Oct 11, 2004
  4. shruds
    Replies:
    1
    Views:
    835
    John C. Bollinger
    Jan 27, 2006
  5. Hicham Mouline
    Replies:
    5
    Views:
    2,378
    James Kanze
    Dec 19, 2008
Loading...

Share This Page