Hey folks, another question - hopefully someone can shed some light on this for me. I'm attempting to implement an improved foreach loop using scriptlets in JSP and I've run into something of an issue.
I'm rendering a tree of folders in my view using a LinkedList of CabinetTreeObj objects. Each of the CabinetTreeObj objects in the LinkedList contains a CabinetFolder object, which contains information such as its parent, name, description, etc, and an Integer grouping, used to identify its depth.
This is instantiated and populated within my servlet, which then simply passes the LinkedList to the view as an attribute, and is rendered accordingly as it iterates through.
I originally used <c:ForEach> to iterate through the list and it worked fine... but I had a few problems communicating values between JSTL and scriptlet code using PageContext. Instead, I decided to write the whole section as a scriptlet.
When using a scriptlet, instead of iterating through the list as it did using <c:forEach>, it threw an exception.
I'm using Tomcat 5.5. I used System.getProperty("java.vm.version") to confirm the compiler version as 1.5.0_06-b05 (verifying that the improved for loop is supported in JSP, hopefully!).
Judging from the exception, it seems to expect: for (iterator; condition; increment)
Rather than: for (Object name: names)
The exception thrown is as follows:
May 30, 2006 2:59:42 PM org.apache.catalina.core.ApplicationDispatcher invoke SEVERE: Servlet.service() for servlet jsp threw exception org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 110 in the jsp file: /WEB-INF/web/filecabinet/cabinet.jsp Generated servlet error: Syntax error on token ":", ; expected
An error occurred at line: 110 in the jsp file: /WEB-INF/web/filecabinet/cabinet.jsp Generated servlet error: Syntax error on token ")", delete this token
An error occurred at line: 110 in the jsp file: /WEB-INF/web/filecabinet/cabinet.jsp Generated servlet error: Syntax error, insert "; ) Statement" to complete ForStatement
My scriptlet code is as follows:
Thanks in advance! [ May 30, 2006: Message edited by: Robert Pruett ]