Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

size of list in JSTL

 
pankaj kapoor
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64858
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64858
86
IntelliJ IDE Java jQuery Mac Mac OS X
 
pankaj kapoor
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8927
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using attributes like isELIgnored="false" would not work in JSP 1.2.
 
Stefan Evans
Bartender
Posts: 1722
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64858
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic