wood burning stoves 2.0*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes ClasscastException when using c:foreach 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 » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "ClasscastException when using c:foreach" Watch "ClasscastException when using c:foreach" New topic
Author

ClasscastException when using c:foreach

fred crocket
Greenhorn

Joined: May 19, 2010
Posts: 2
Hi there,

I've read that all of the standard collection types provided by the Java platform are supported by the <c:forEach> tag. In addition, you can use this action to iterate through the elements of an array, including arrays of primitives.

So, I don't understand why I get a Classcastexception when providing something else than an array :

org.apache.jasper.JasperException: java.lang.ClassCastException: java.util.ArrayList cannot be cast to [Ljava.lang.String;
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:522)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:416)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
com.example.Myclass.doGet(Myclass.java:38)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


com.example.Myclass :



theView.jsp :



I'm deploying on Tomcat 6.0.20 (and using it's jstl.jar and standard.jar)

Can anyone explain what's causing this ?

Many thanks in advance
Raza Mohd
Ranch Hand

Joined: Jan 20, 2010
Posts: 247

http://www.coderanch.com/t/293519/JSP/java/iterating-ArrayList-forEach

hope you can get your query resolved

thanks


Good luck!!
A small leak can sink a Gigantic ship.>
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1627
    
  23

Hi Fred,

I have copied your code into my Tomcat5.5 server and it is working perfectly.
output:

Scarface
Goodfellas
Casino
The Godfather


are you using jstl1.1?

for Tomcat6.0 you need jstl1.2 seeTagLibDef

Regards,
Frits
fred crocket
Greenhorn

Joined: May 19, 2010
Posts: 2
Hello Frits,

I'm using jstl.jar and standard.jar, provided by tomcat in its webapps/examples folder. That makes it jstl1.1, right ?

Meanwhile it tried to include the page directive



reading the thread Raza Mohd suggested.

Then it worked, so I thought that this was the reason. But when I remove the page directive again (and restart Tomcat) it still works !

In other words, I can't reproduce the ClasscastExcption...

I'm glad my problem has disappeared, although I would like to know what the reason of the failure was.

Thanks for your interest !
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1627
    
  23

I'm using jstl.jar and standard.jar, provided by tomcat in its webapps/examples folder. That makes it jstl1.1, right ?

Yes, those jars in combination with your taglib directive. (I assume that you copied them in your web-app-root/WEB-INF/lib directory)

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" isELIgnored="false" %>

the IsELIgnored is only useful if your web.xml is in a container using servlet2.3 specs (there the Expression Language is switched off by default). Most likely yours is a servlet2.4 (or servlet2.5).

I have no idea what went wrong, but anyway it is solved!

Regards,
Frits
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: ClasscastException when using c:foreach
 
Similar Threads
Jstl error
Error:Unable to get connection, DataSource invalid
how check javabean giving to other component correct data
No suitable driver
Data Alignment