jsp - 使用 ModelAndView 传递对象,然后使用 JSTL 解析

标签 jsp spring-mvc jstl

这似乎应该有效,但我似乎无法弄清楚为什么,希望一双新的眼睛能够发现一些非常明显的东西......

我将一个对象从我的 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/

相关文章:

java - Spring MVC,Java : Creating URL for image saved on FileSystem

java - 在 JSTL 中接受对象

java - 在 Spring MVC 中以 XML 形式获取 SOAP 请求

java - EL1008E :(pos 8):Property or field cannot be found on object of type '...security.web.access.expression.WebSecurityExpressionRoot' maybe not public?

java - JSTL for every, var 包含方括号

java - 通过 JSTL 在 JSP 页面上显示 ArrayList

java - 还有其他方法可以从 JSP 中的 bean 获取属性吗?

java - 发送电子邮件 html 表单

java - Struts 2.0 请求 Bean 对象获取参数值

jquery - 如何在JSP中正确使用JQuery Datatable?