This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes JSP and the fly likes size of list  in JSTL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "size of list  in JSTL" Watch "size of list  in JSTL" New topic
Author

size of list in JSTL

pankaj kapoor
Greenhorn

Joined: Sep 22, 2005
Posts: 17
I am trying to print the size of list with the following code in jsp
<%
List ll = new ArrayList();
ll.add("India");
ll.add("Pakistan");
%>
<c ut value="${fn:length(ll)}" />
but I am not able to do so.

The tablib I have included in jsp is
<%@ taglib uri='http://java.sun.com/jstl/functions' prefix='fn' %>
but error 'broken link' comes

I have included standard.jar in classpath

could anyone suggest to me what is the solution to this problem.

Thanks in advance
Balasubramani Dharmalingam
Ranch Hand

Joined: Dec 06, 2004
Posts: 116
try this,


and also u have to add jstl.jar and standard.jar to the WEB-INF/lib folder of your application.

Above code was tested in :
Tomcat 5.0.28 ,JSTL 1.1


Balasubramani SD,<br />SCJP 1.4,SCWCD 1.4,SCJP 5.0<br /><a href="http://sd.balasubramani.googlepages.com" target="_blank" rel="nofollow">www.sd.balasubramani.googlepages.com</a>
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61105
    
  66

Check the JSP FAQ to make sure that you have everything set up properly for a JSP 2.0 and Servlets 2.4 web application.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61105
    
  66

This one.
pankaj kapoor
Greenhorn

Joined: Sep 22, 2005
Posts: 17
I tried this code
<%@ page import="java.util.*" %><%@ page isELIgnored="false" %><%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %><%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <%List ll = new ArrayList();ll.add("India");ll.add("Pakistan"); request.setAttribute( "ll" , ll ) ;%><c ut value="${fn:length(ll)}"

but it does not work. I suppose there is some problem with the JSP version I am using.(JSP 1.2) but even 1.2 version supports this.
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

Using attributes like isELIgnored="false" would not work in JSP 1.2.


Groovy
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1018
In JSTL1.0 there is no way using EL to get the size of a collection.
You can tell if it is empty or not, but thats it.

This is one of the flaws that JSTL1.1 fixed (through providing the functions)
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61105
    
  66

To do what you want to do you need JSP 2.0 and JSTL 1.1. Anything earlier will not support the fn:length function.

Your web app also needs to be a Servlet 2.4 web app. See the JSP FAQ I pointed to.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: size of list in JSTL