Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

size of list in JSTL

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67618
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67618
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This one.
 
pankaj kapoor
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 8944
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Using attributes like isELIgnored="false" would not work in JSP 1.2.
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67618
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic