javax.servlet.ServletException: javax.servlet.jsp.JspTagException: Don’t know how to iterate over supplied “items” in

Caused by: javax.servlet.ServletException: javax.servlet.jsp.JspTagException: Don’t know how to iterate over supplied “items” in <forEach> That will happen when the <c:forEach items> does not refer a valid object over which it can iterate. The object should be an Object[] (a plain array), a Collection, Map, Iterator, Enumeration or String (see also source code). Anything else can’t … Read more

java.lang.NoClassDefFoundError: javax/servlet/jsp/jstl/core/Config

java.lang.NoClassDefFoundError: javax/servlet/jsp/jstl/core/Config As the package name hints, the mentioned class is part of JSTL. The exception is clearly telling that the class definition file of the mentioned class cannot be found in the runtime classpath. I.e. the Config.class file or at least the JAR file containing that class is missing in webapp’s runtime classpath. JSTL … Read more

How to access objects in EL expression language ${}

The expression ${foo} uses behind the scenes JspContext#findAttribute() which searches for attributes in PageContext, HttpServletRequest, HttpSession and ServletContext in this order by their getAttribute(“foo”) method whereby foo from ${foo} thus represents the attribute name “foo” and returns the first non-null object. So, if you do in a servlet ArrayList<Person> persons = getItSomehow(); request.setAttribute(“persons”, persons); // … Read more

EL access a map value by Integer key

Initial answer (EL 2.1, May 2009) As mentioned in this java forum thread: Basically autoboxing puts an Integer object into the Map. ie: map.put(new Integer(0), “myValue”) EL (Expressions Languages) evaluates 0 as a Long and thus goes looking for a Long as the key in the map. ie it evaluates: map.get(new Long(0)) As a Long … Read more

How to iterate an ArrayList inside a HashMap using JSTL?

You can use JSTL <c:forEach> tag to iterate over arrays, collections and maps. In case of arrays and collections, every iteration the var will give you just the currently iterated item right away. <%@ taglib prefix=”c” uri=”http://java.sun.com/jsp/jstl/core” %> <c:forEach items=”${collectionOrArray}” var=”item”> Item = ${item}<br> </c:forEach> In case of maps, every iteration the var will give … Read more

Evaluate empty or null JSTL c tags

How can I validate if a String is null or empty using the c tags of JSTL? You can use the empty keyword in a <c:if> for this: <c:if test=”${empty var1}”> var1 is empty or null. </c:if> <c:if test=”${not empty var1}”> var1 is NOT empty or null. </c:if> Or the <c:choose>: <c:choose> <c:when test=”${empty var1}”> … Read more

Collect and save submitted values of multiple dynamic HTML inputs back in servlet

Given this simplified model: public class Item { private Long id; private String foo; private String bar; // … } Here’s how you can do it provided ${items} is List<Item>: <c:forEach items=”${items}” var=”item”> <tr> <td> <input type=”hidden” name=”id” value=”${item.id}” /> <input name=”foo_${item.id}” value=”${fn:escapeXml(item.foo)}” /> </td> <td> <input name=”bar_${item.id}” value=”${fn:escapeXml(item.bar)}” /> </td> </tr> </c:forEach> (note the … Read more

javax.el.PropertyNotFoundException: Property ‘foo’ not found on type com.example.Bean

javax.el.PropertyNotFoundException: Property ‘foo’ not found on type com.example.Bean This literally means that the mentioned class com.example.Bean doesn’t have a public (non-static!) getter method for the mentioned property foo. Note that the field itself is irrelevant here! The public getter method name must start with get, followed by the property name which is capitalized at only … Read more