Can you tell me what’s wrong in this code?
I’m using Spring MVC to send data. The scriplet is working but the jstl throws some error though both scriplet and jstl performs same action.
<%@page import="java.util.ArrayList"%>
<%@page import="biz.canisrigel.scg.common.RssParser.Item"%>
<%@taglib prefix="c" uri="http://java.sun.com/jstl/core"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Twitter</title>
</head>
<body>
<%
ArrayList<Item> feeds = (ArrayList<Item>) request
.getAttribute("feeds");
for (Item tfeed : feeds) {
out.println(tfeed.description);
}
%>
<c:forEach var="tfeed" items="${feeds}">
<c:out value="${tfeed.description}" />
</c:forEach>
</body>
</html>
Can you point where am I going wrong? Error thrown is javax.servlet.ServletException: javax.servlet.jsp.JspException: An error occurred while evaluating custom action attribute “value” with value “${tfeed.description}”: Unable to find a value for “description” in object of class “biz.canisrigel.scg.common.RssParser$Item” using operator “.” (null)
Added c:if as per Ravi’s suggestion. Following is the error:
An error occurred while evaluating custom action attribute “test” with value “${not empty tfeed.description}”: Unable to find a value for “description” in object of class “biz.canisrigel.scg.common.RssParser$Item” using operator “.” (null)
Looking to your code, It seems the Item class does not have the getter method for the property ‘description’. Please add it and verify it again It should work. Make sure the getter method is available when ever you access any property through EL.