【问题标题】:javax.el.PropertyNotFoundException: in the JSP page of a Spring MVC Applicationjavax.el.PropertyNotFoundException:在 Spring MVC 应用程序的 JSP 页面中
【发布时间】:2011-07-28 02:58:15
【问题描述】:

我在数据库中有 2 个表(机场和中途停留)。 我写了一个 SQL 连接查询,得到一个包含两个表中的字段的结果集。 为了映射结果,我创建了一个自定义对象“VbResult”。 (DB中没有这个域对象对应的表)

请在下面找到域对象、控制器和视图的代码: 当我调用主页时,我得到了异常,尽管我在 VbResult 类中有字段 ressrc。

(或)使用自定义对象作为 VbResult 是错误的 - 只是为了 View ,没有表存在?

我被困了很长时间..我在这里错过了什么!请告诉我!

提前致谢

javax.el.PropertyNotFoundException:在类型 com.datacaliper.vbuddy.domain.VbResult 上找不到属性“ressrc”

域对象:VbResult

public class VbResult implements java.io.Serializable{  
private static final long serialVersionUID = -3606761414209638631L;  
private Integer resid;  
private String resairline;  
private String resemail;  
private String ressrc;  
private String resdes;  
//private String res_airline;     

public VbResult(){  }  

public VbResult(Integer id, String airline, String email,  
        String source, String destination) {  
    this.resid= id;  
    this.resairline = airline;  
    this.resemail = email;  
    this.ressrc = source;  
    this.resdes = destination;  
}  

public Integer getId() {  
    return this.resid;  
}  
public void setId(Integer id) {  
    this.resid = id;  
}  
public String getAirline() {  
    return this.resairline;  
}  
public void setAirline(String airline) {  
    this.resairline = airline;  
}  
public String getEmail() {  
    return this.resemail;  
}  
public void setEmail(String email) {  
    this.resemail = email;  
}  
public String getSource() {  
    return this.ressrc;  
}  
public void setSource(String source) {  
    this.ressrc = source;  
}  
public String getDestination() {  
    return this.resdes;  
}  
public void setDestination(String destination) {  
    this.resdes = destination;  
}  
}  

控制器代码:

@Controller  
@RequestMapping({"/","/main"})  
public class MainController {  
protected static Logger logger = Logger.getLogger("controller");  
@Resource(name="PostService")  
private PostService postService;  
@RequestMapping(value = "/home", method = RequestMethod.GET)  
public String getStopovers(Model model) {  
logger.debug("Received request to show all Posts");  
// Retrieve all posts by delegating the call to PostService  
List<VbResult> stops = postService.getAll();  
// Attach persons to the Model  
model.addAttribute("stops", stops);  
return "homepage";       
}   
}  

JSPPage

<c:forEach items="${stops}" var="stop">  
<tr>  
<td><c:out value="${stop.ressrc}" />  
</td>  
<td><c:out value="${stop.resdes}" />  
</td>  
</tr>  
</c:forEach>  

【问题讨论】:

    标签: java jsp spring-mvc jstl el


    【解决方案1】:

    javax.el.PropertyNotFoundException:在类型 com.datacaliper.vbuddy.domain.VbResult 上找不到属性“ressrc”

    这基本上说明在具有完整限定名称 com.datacaliper.vbuddy.domain.VbResult 的类上没有名称为 getRessrc() 的 getter 方法。

    确实,没有这样的方法。你称它为getSource()。相应地修复您的 JSP 代码。

    <c:out value="${stop.source}" /> 
    

    修复此问题后您将获得的 resdes 上的新 PropertyNotFoundException 现在应该足够自我解释了 ;)

    【讨论】:

    • 是的!谢谢回复。我只是改变了它,就像微风一样工作
    猜你喜欢
    • 2012-06-22
    • 2012-12-28
    • 2012-08-29
    • 2012-09-30
    • 2012-11-02
    • 1970-01-01
    • 2019-07-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多