0

I went through all of the posts related to JSTL and arrayList , still couldn't find the solution.

I have been trying to iterate an ArrayList over a jsp file using taglib. I have included latest jstl 1.2 jar in my build path. Have configured the taglib properly.

But still get an error infront of the line which uses

 <c:forEach>

tag. It says

 <c:foreach>not recognized!, 

yes it is showing error with a 'e' in forEach !

Please find my code below.

Controller code :

   List<String> rolesList = new ArrayList<String>();
   rolesList.add(ga.getAuthority());

JSP Code :

    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

   <select>
      <c:forEach items="${rolesList}" var="role">
             <option>${role}</option>
        </c:forEach>
    </select> 
Napster
  • 1
  • 1

3 Answers3

0

Do you have the jstl 1.2 jar in your RUNTIME classpath? That's where it counts!

Tommy B
  • 187
  • 2
  • 8
  • I'm still a rookie, it would be great if you could elaborate that. I have included it as an external jar in my buildpath along with other jars like spring, hibernate etc., Is there another place where i should drop this jstl jar? – Napster Apr 18 '12 at 08:41
  • If your build tool builds a proper war, then you should find it in the lib folder inside the war file. A war file is a zip file so any zip file utility will be able to open for you to have a look inside. There's always the option of putting a copy of the file in your application server's lib folder. If you're using Tomcat you'll find it at the top level in the Tomcat folder. – Tommy B Apr 18 '12 at 13:25
  • I get what RUNTIME classpath means now.Thanks for the explainiation @Tommy B the JSTL 1.2 jar is there inside it, but the problem still persists – Napster Apr 19 '12 at 10:14
0

I am also faced same problem when i include jsf in jsp

Then i download latest jstl jar and included inside project lib,

Then added below code in header

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

and changed $ into # beacause it not visible array list in runtime, i changed your code its working for me

your code

<select>
      <c:forEach items="${rolesList}" var="role">
             <option>${role}</option>
        </c:forEach>
</select> 

I changed into

 <select>
      <c:forEach var="list" items="#{Test.rolesList}" var="role">
             <option>${list.role}</option>
        </c:forEach>
</select>

Note: Test is a Managedbean @ManagedBean(name="Test") in back bean code

Thank you

Praveenkumar_V
  • 1,394
  • 2
  • 11
  • 19
  • As to using `#{}` instead of `${}`, OP doesn't seem to indicate anywhere that he is using JSF. – BalusC Nov 07 '12 at 19:46
0

I have included latest jstl 1.2 jar in my build path.

This is not the entirely correct approach.

Assuming that you're using Eclipse, the JAR file should be dropped in the project's /WEB-INF/lib folder. Really nothing more needs to be done. You do not need to fiddle in the Build Path property of the project. You should undo everything which you did there in an attempt to "fix" the problem.

If you really insist in having the JAR outside the project's /WEB-INF/lib folder for some reason, then you should not have edited the Build Path property, but instead the Deployment Assembly property. This will take care that the JAR also actually ends up in the /WEB-INF/lib of the built and deployed WAR.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555