JSTL <c:set> tag with <fmt> tag

Posted on 2006-03-20
Last Modified: 2013-11-24
Hi. I don't know much about JSTL, but someone with some knowledge was trying to help me out. Basically I'm trying to set a variable in JSTL with value equal to something referenced by a <fmt> tag. Then I try to get the value of this variable in a scriptlet through the pageContext. The code below doesn't work, however. All I'm getting is an empty string in the scriptlet. Any help would be appreciated.

      <c:set var="selectedValuePresented" value="<fmt:message key='<%= ResourceKeys.DF_SELECT %>'/>" />

      String selectedValuePresented = String.valueOf (pageContext.getAttribute("selectedValuePresented"));
Question by:willi_gamboa
    LVL 4

    Accepted Solution

    You can't nest custom tags as attributes to other custom tags.
    However, the c:set takes its value either from the "value" attribute, or the nested content.
    You can probably do it like this:
     <c:set var="selectedValuePresented"><fmt:message key='<%= ResourceKeys.DF_SELECT %>'/></c:set>
    I am presuming you have a JSP2.0 container (eg Tomcat 5), or are using the "runtime" version of JSTL.

    I would question your need for scriptlet code though.  The whole point of JSTL is to minimize it in pages.
    LVL 16

    Assisted Solution


    I think that <fmt> can also be used to set variable. Please do like
    <fmt:message key='<%= ResourceKeys.DF_SELECT %>' var="selectedValuePresented" />

    Please try that out


    Author Comment

    Thank you. Both approaches work. Regarding minimizing scriptlet code, I completely agree. However, I'm a front end developer whose focus is on DHTML. So any quick way to get the Java developers' code to work with my front end stuff will work for me.
    LVL 16

    Expert Comment


    Glad I could help


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Suggested Solutions

    Title # Comments Views Activity
    java ^ examples 8 48
    nested interface 5 29
    dividesSelf challange 15 54
    Receive file in Servlet 1 25
    Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
    Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
    The viewer will learn how to implement Singleton Design Pattern in Java.
    This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now