javax.el.PropertyNotFoundException:类'java.lang.String'没有该属性 [英] javax.el.PropertyNotFoundException: The class 'java.lang.String' does not have the property
问题描述
我正在创建Sample Spring MVC应用程序.在我的Controller类中,我定义如下:
I am creating Sample Spring MVC application. In my Controller class I have define like this:
Map<String, Object> myModel = new HashMap<String, Object>();
myModel.put("now", now);
myModel.put("products", this.productManager.getProducts());
return new ModelAndView("hello", "model", myModel);
当我将以下部分放入我的JSP文件时,出现了javax.el.PropertyNotFoundException
异常
When I put following part in my JSP file i got javax.el.PropertyNotFoundException
exception
<c:forEach items="${model.products}" var="prod">
<c:out value="${prod.description}"/> <i>$<c:out value="${prod.price}"/></i><br><br>
</c:forEach>
这是我的全部例外:
javax.el.PropertyNotFoundException: The class 'java.lang.String' does not have the property 'description'.
但是在我的域类中,private Sting description
属性具有公共获取器和设置器. Product
类是公共类.
But in my domain class private Sting description
property has public getter and setter. That Product
class is public one.
产品类别:
public class Product implements Serializable {
private String description;
private Double price;
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Double getPrice() {
return price;
}
public void setPrice(Double price) {
this.price = price;
}
}
PS:
如果我这样使用,那就可以了
If I used like this it's working
<c:forEach items="${model.products}" var="prod" varStatus="status">
<c:out value="${model.products[status.count -1].description}"/> <i>$<c:out value="${model.products[status.count -1].price}"/></i><br><br>
</c:forEach>
但是推荐的解决方案不起作用:(
But recommended solution not working :(
推荐答案
也许检查您的taglib导入:
Maybe check your taglib import:
OLD
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
新
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
您的Product
类及其获取器是否可访问?广义上讲,我是public
吗?
Is your Product
class and its getters accessible? By this I broadly mean are they public
?
请参见 http://forum.springsource.org /showthread.php?58420-Problem-with-javax.el.PropertyNotFoundException .
这篇关于javax.el.PropertyNotFoundException:类'java.lang.String'没有该属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!