spring javax.el.PropertyNotFoundException:类“java.lang.String”没有属性
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7318004/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
javax.el.PropertyNotFoundException: The class 'java.lang.String' does not have the property
提问by Chandana
I am creating Sample Spring MVC application. In my Controller class I have define like this:
我正在创建示例 Spring MVC 应用程序。在我的 Controller 类中,我定义如下:
Map<String, Object> myModel = new HashMap<String, Object>();
myModel.put("now", now);
myModel.put("products", this.productManager.getProducts());
return new ModelAndView("hello", "model", myModel);
When I put following part in my JSP file i got javax.el.PropertyNotFoundExceptionexception
当我将以下部分放入 JSP 文件时,出现javax.el.PropertyNotFoundException异常
<c:forEach items="${model.products}" var="prod">
<c:out value="${prod.description}"/> <i>$<c:out value="${prod.price}"/></i><br><br>
</c:forEach>
Here is my full exception :
这是我的完整例外:
javax.el.PropertyNotFoundException: The class 'java.lang.String' does not have the property 'description'.
But in my domain class private Sting descriptionproperty has public getter and setter. That Productclass is public one.
但是在我的域类private Sting description属性中有公共 getter 和 setter。那Product堂课是公开课。
Product class:
产品类别:
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:
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 :(
但推荐的解决方案不起作用:(
采纳答案by Paul Grime
Maybe check your taglib import:
也许检查您的 taglib 导入:
OLD
老的
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
NEW
新的
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
Is your Productclass and its getters accessible? By this I broadly mean are they public?
你的Product类和它的 getter 是否可以访问?我广义上的意思是他们public?
See http://forum.springsource.org/showthread.php?58420-Problem-with-javax.el.PropertyNotFoundException.
请参阅http://forum.springsource.org/showthread.php?58420-Problem-with-javax.el.PropertyNotFoundException。
回答by loreii
This happen when you are passing a String to an EL operation c:forEach instead of an iterable element, in the following example I miss the '$' so it's passing the exact String without variable resolution.
当您将字符串传递给 EL 操作 c:forEach 而不是可迭代元素时,会发生这种情况,在下面的示例中,我错过了 '$',因此它传递了没有可变分辨率的确切字符串。
<c:forEach var="o" items="{operations}">
The next is right because operation is a String[] in my code
下一个是对的,因为在我的代码中操作是一个 String[]
<c:forEach var="o" items="${operations}">
回答by NimChimpsky
Try this:
尝试这个:
<c:forEach items="${model['products']}" var="oneProduct">
<c:out value="${oneProduct.description}"/> <i>$<c:out value="${oneProduct.price}"/>
</i><br><br>
</c:forEach>
And check the capitalization of you gettters and setters, should be getDescription()
并检查你的 getter 和 setter 的大小写,应该是 getDescription()

