这似乎应该有效,但我似乎无法弄清楚为什么,希望一双新的眼睛能够发现一些非常明显的东西......
我将一个对象从我的 Controller 传递到我的 jsp 文件,但是尝试用 EL 解析该对象是行不通的,它作为一个 scriptlet 工作,这让我发疯:)
使用Spring 3.0 MVC
型号:
public class Table {
private String mId;
private ArrayList<Row> mRows;
public String getId() {
return mId;
}
Controller :
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
最佳答案
将private String mId;
更改为private String id;
和
${table.getId}
到 ${table.id}
你不需要也不能使用这样的访问器方法。
如果必须是 mId 则更改
public String getId()
到public String getMid()
和
${table.getId}
到 ${table.mId}
关于jsp - 使用 ModelAndView 传递对象,然后使用 JSTL 解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8117840/