使用ModelAndView传递Object,然后使用JSTL进行解析

时间:2011-11-14 05:55:48

标签: jsp spring-mvc jstl

这似乎应该可行,但我似乎无法弄明白为什么,希望一副新鲜的眼睛可以发现一些非常明显的东西......

我将一个对象从我的控制器传递给我的jsp文件,但是试图用EL解析对象是行不通的,但它起到了一个小脚本的作用,它让我抓狂:)

使用Spring 3.0 MVC

型号:

public class Table {

private String mId;
private ArrayList<Row> mRows;

public String getId() {
    return mId;
}

控制器:

Table table = new Table();
table.setId("test");

ModelAndView mav = new ModelAndView();
mav.addObject("table",table);
mav.setViewName("report");

return mav;

JSP文件:

<!--  this works -->

<%
Table table = (Table)request.getAttribute("table");
System.out.println(table.getId());
%>

<!--  this does not work -->

${table.getId}

错误:

org.apache.jasper.JasperException: An exception occurred processing JSP page /WEB-INF/jsp/report.jsp at line 33

30: 
31:     <!--  this dows not work -->
32: 
33:     ${table.getId}
34: 
35: </body>
36: </html>

javax.el.PropertyNotFoundException: Property 'getId' not found on type com.platform.server.portal.model.Table

1 个答案:

答案 0 :(得分:3)

private String mId;更改为private String id;

${table.getId}${table.id}

你不需要也不能使用这样的访问方法。

如果必须是mId则更改

public String getId()public String getMid()

${table.getId}${table.mId}