?
Solved

JSTL Equivalent code

Posted on 2009-04-28
7
Medium Priority
?
781 Views
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() %>
0
Comment
Question by:softechnics
  • 3
  • 2
  • 2
7 Comments
 
LVL 28

Accepted Solution

by:
rrz earned 2000 total points
ID: 24256061
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="http://java.sun.com/jsp/jstl/core" prefix="c"%> 
<%
  Hashtable table = new Hashtable();
  table.put("one","first");
  table.put("two","second");
  table.put("three","third");
%>
 
<c:forEach items="<%=table%>" var="current">
                    key is ${current.key} value is ${current.value}<br/>
</c:forEach>
 
myAddress is ${pageContext.request.localAddr}: ${pageContext.request.localPort}<br/>
sessionId is ${pageContext.request.session.id}

Open in new window

0
 
LVL 11

Expert Comment

by:Manish
ID: 24257467

${requestScope.localAddr}
${requestScope.localPort}
0
 

Author Comment

by:softechnics
ID: 24259953
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?

Bummer!

Can you direct me to a good reference page that describes the above objects/methods?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 28

Expert Comment

by:rrz
ID: 24260646
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  
http://java.sun.com/javaee/5/docs/tutorial/doc/bnakc.html   


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

Expert Comment

by:rrz
ID: 24260848
See also  see "Unified Expression Language" at  
http://java.sun.com/javaee/5/docs/tutorial/doc/bnahq.html
0
 

Author Comment

by:softechnics
ID: 24261571
karanw,

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.
0
 
LVL 11

Expert Comment

by:Manish
ID: 24267136
No problem.
Thanks for explanation.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
A solution for Fortify Path Manipulation.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month13 days, 11 hours left to enroll

749 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