如何将对象从arraylist中获取到jsp中,并将其添加到控制器内的modelAndView中

时间:2014-11-19 11:55:28

标签: java spring jsp

目前我正在开发Spring MVC。我要将数据从控制器传输到视图。我有一个包含对象的arraylist。它已被添加到控制器内的ModelAndView中,以便我可以将它用于JSP页面。

model.addObject("results",results);

我想使用值将其打印成表格形式,但我无法这样做。 我这样做

${results.get(0).getParameterName() }

但显示错误

The function get must be used with a prefix when a default namespace is not specified
一切都运转良好。有人可以帮我解决这个问题。

Servlet.service() for servlet spring-dispatcher threw exception
org.apache.jasper.JasperException: /WEB-INF/ConfigureApplication.jsp(45,86) The function get must be used with a prefix when a default namespace is not specified
    at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:39)
    at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:405)
    at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:146)
    at org.apache.jasper.compiler.Validator$1FVVisitor.visit(Validator.java:1243)
    at org.apache.jasper.compiler.ELNode$Function.accept(ELNode.java:122)
    at org.apache.jasper.compiler.ELNode$Nodes.visit(ELNode.java:193)
    at org.apache.jasper.compiler.ELNode$Visitor.visit(ELNode.java:234)
    at org.apache.jasper.compiler.ELNode$Root.accept(ELNode.java:53)
    at org.apache.jasper.compiler.ELNode$Nodes.visit(ELNode.java:193)
    at org.apache.jasper.compiler.Validator$ValidateVisitor.validateFunctions(Validator.java:1266)
    at org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:607)
    at org.apache.jasper.compiler.Node$ELExpression.accept(Node.java:896)
    at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
    at org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2213)
    at org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2219)
    at org.apache.jasper.compiler.Node$Root.accept(Node.java:456)
    at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
    at org.apache.jasper.compiler.Validator.validate(Validator.java:1489)
    at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:166)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:295)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:276)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:264)
    at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:303)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
    at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:209)
    at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:267)
    at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1221)
    at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1005)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:952)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
    at java.lang.Thread.run(Thread.java:722)

1 个答案:

答案 0 :(得分:4)

${...}中的字词位于jsp Expression Language而不是java。 List的成员可以像数组成员和bean属性一样按名称访问。因此你应该尝试:

${results[0].parameterName}