Share vars between scriptlet and jstl?

Discussion in 'Java' started by Robert Mark Bram, Mar 20, 2005.

  1. Hi All!

    Can variables be shared between 'contexts' like this?


    <%
    Table i = new Table();
    %>
    <c:set var="noRows" value="${i.noRows}" />
    <c:set var="noCols" value="${i.noCols}" />


    Alternatively, how would I instantiate a Table object with a JSTL tag?

    Rob
    :)
    Robert Mark Bram, Mar 20, 2005
    #1
    1. Advertising

  2. Robert Mark Bram

    Ryan Stewart Guest

    "Robert Mark Bram" <none> wrote in message
    news:423d06c9$0$5598$...
    > Hi All!
    >
    > Can variables be shared between 'contexts' like this?
    >
    >
    > <%
    > Table i = new Table();
    > %>
    > <c:set var="noRows" value="${i.noRows}" />
    > <c:set var="noCols" value="${i.noCols}" />
    >
    >
    > Alternatively, how would I instantiate a Table object with a JSTL tag?
    >

    JSTL operates on variables stored in one of the four contexts: page, request,
    session, and application. Simply declaring a variable does not place it in any
    of those scopes. To do so, you invoke the setAttribute method on the object
    corresponding to whichever scope in which you want to store the variable. The
    objects are pageContext, request, session, and application. So to make your
    Table available to JSTL, use:
    <%
    Table i = new Table(); // What kind of name is "i"?
    pageContext.setAttribute("i", i);
    %>

    That will store a reference to the object referenced to by variable i in the
    page scope with a name of "i", making it accessible to JSTL. You could also use
    request.setAttribute("i", i);

    or session.set... or application.set...

    Better to get all scriplets out of your JSPs and do that kind of thing in a
    controller of some sort.
    Ryan Stewart, Mar 20, 2005
    #2
    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. Jon

    app vars and cache vars

    Jon, Dec 14, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    380
  2. ramakrishna
    Replies:
    0
    Views:
    1,226
    ramakrishna
    May 4, 2006
  3. Linuxguy123
    Replies:
    7
    Views:
    667
    Paddy O'Loughlin
    Feb 20, 2009
  4. caccolangrifata
    Replies:
    18
    Views:
    385
    Chris Torek
    Jul 22, 2011
  5. Saraswati lakki
    Replies:
    0
    Views:
    1,290
    Saraswati lakki
    Jan 6, 2012
Loading...

Share This Page