Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

jstl question  RSS feed

 
Naresh Chaurasia
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
i have the following code in servlet

String string1 []={"one","two"};
String string2 []={"one2","two2"};
List list = new ArrayList();
list.add(string1);
list.add(string2);
req.setAttribute("list",list);

req.getRequestDispatcher("/HFSJ/chap09/437_coding.jsp").forward(req,res);


437_coding.jsp
--------------

length : ${list}

--------------------------------------

I want to know the length of list array using JSTL. How can i do that.

thnx in advance

NC
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please follow the guidelines listed at the top of the forum and let us know what versions you are using.
 
Harish Madhavan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to use the JSTL functions.
Something like ${fn:length(requestScope.list)}. It supports finding both collection size or the string length. Look at JSTL documentation for functions http://java.sun.com/products/jsp/jstl/1.1/docs/tlddocs/fn/length.fn.html.

Cheers,
Harish
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
... which only works with JSTL 1.1, which is why I asked about versions, and why it is important to provide this information when posting questions.
 
Hiren Pathak
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a way to get the same functionality in JSTL 1.0 ??

Thnx
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. EL function were introduced with JSP 2.0.

If your container supports JSP 2.0, you should be using JSTL 1.1 and there isn't an issue.

If your container supports JSP 1.2, you should be using JSTL 1.0 and EL functions are not supported since JSP 1.2 doesn't support them.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can always write your own custom action to do it. Also, if you're a Struts user, there's a Struts tag the does it (<bean:size>).
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!