wood burning stoves*
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 Murach's Java Servlets and JSP this week in the Servlets 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: 60766
    
  65

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: 60766
    
  65

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: 8904

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


Groovy
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1016
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: 60766
    
  65

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: size of list in JSTL
 
Similar Threads
please explain Generics compilation error
Generic question
Generics
Generics
Linked List need help