JSTL Equivalent code

Posted on 2009-04-28
Last Modified: 2013-11-24
I'm converting an existing JSP page using scriplets to JSTL. Can someone help me out here. I need to convert the following JSP code/scriplets to JSTL.

<jsp:useBean id="organization" scope="session" class="com.xxxx.Organization" />
Hashtable orgs = <%= organization.getAllOrgs() %>

String myAddress = <%= request.getLocalAddr() %>:<%= request.getLocalPort() %>
String sessionId = <%= request.getSession().getId() %>
Question by:softechnics
    LVL 27

    Accepted Solution

    You use the useBean the same way.  For the address and session id, just use EL.  
    Please look at the demo code below here.
    <%@ page import="java.util.Hashtable" %>
    <%@taglib uri="" prefix="c"%> 
      Hashtable table = new Hashtable();
    <c:forEach items="<%=table%>" var="current">
                        key is ${current.key} value is ${current.value}<br/>
    myAddress is ${pageContext.request.localAddr}: ${pageContext.request.localPort}<br/>
    sessionId is ${}

    Open in new window

    LVL 11

    Expert Comment



    Author Comment

    So, JSTL is not all-inclusive? From your sample code above, it looks like I still have to revert back to scriplets to do some processing that JSTL cannot handle - like the handling of the Hashtable?


    Can you direct me to a good reference page that describes the above objects/methods?
    LVL 27

    Expert Comment

    I just created the hashtable in a scriptlet for my example. I assumed that your hashtable was coming from somewhere else. For your case above here, you can use  
    <c:forEach items="${organization.allOrgs}" var="current">
    For reference  see Chapter 7  at    

    karanw,  requestScope is an implicit variable to access all request scope varibles. It does provide access to the request object methods.  
    LVL 27

    Expert Comment

    See also  see "Unified Expression Language" at

    Author Comment


    I'm going to give all the points to rrz@871311. This doesn't imply that your suggestions, in general, don't work. However, they don't work in my environment. I am working on a Symbol MC9090 wireless PDA running WM 5.0. I tried both solutions. His worked, yours did not. Sorry.
    LVL 11

    Expert Comment

    No problem.
    Thanks for explanation.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Suggested Solutions

    Title # Comments Views Activity
    scoresAverage challenge 8 58
    copyEndy  challenge 15 37
    endX challenge 2 30
    wordmultiple challenge 12 61
    This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
    Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
    Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
    Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

    779 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

    12 Experts available now in Live!

    Get 1:1 Help Now