在JSP页面怎么遍历属性关联的属性,看看代码

qq_29808325 2015-07-30 10:28:02
User类代码,忽略getset

@Entity
@Table
public class User {

private Integer id;
private String number;
private String passwd;
private UserMessage useraMessage;
}


UserMessage类代码忽略getset

@Entity
@Table
public class UserMessage {

private Integer id;
private String name;
private String clazz;

@Past
@DateTimeFormat(pattern="yyyy-MM-dd")
private Date birthday;
}


SpringMVC Controller层代码

@Controller()
@RequestMapping("/admin")
public class SpringMVCAdmin {

private AdminService adminService;

@RequestMapping("/getAllUser")
public String getAllUser(Map<String, Object> map) {
map.put("users", adminService.getAllUser());
List<User> l = adminService.getAllUser();
System.out.println("MVCAdmin-->getAllUser-->userMessage.name = "+l.get(0).getUseraMessage().getName());
return "Admin/list";
}
}


list.jsp页面代码

<body>

<table border="1">
<tr>
<td>ID</td>
<td>学号</td>
<td>名字</td>
<td>班级</td>
<td>成绩</td>
<td>删除</td>
</tr>
<c:forEach items="${requestScope.users }" var="u">
<tr>
<td>${u.id }</td>
<td><a href="admin/select/${u.id}">${u.number }</a></td>
<td><a href="admin/select/${u.id}">${u.userMessage.name }</a></td>
<td>${u.userMessage.clazz }</td>
<td><a href="admin/results/${u.userMessage.id }">添加</a></td>
<td><a href="admin/delete/${u.id }">删除</a></td>
</tr>
</c:forEach>
</table>

</body>


user的属性都可以遍历出来,但是遍历不到user.userMessage属性,也拿不到user.userMessage.xxx的东西代码一出现就报错,注掉有关user.userMessage的代码就没问题.这是什么问题啊困扰我几天了,然后我在Controller层加的那句打印的能够正常打印出来
...全文
144 点赞 收藏 5
写回复
5 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
qq137510669 2015-08-04
和眼力无关,看错误信息: Property 'userMessage' not found on ... 的意思是'userMessage' 属性没有找到,而且前台页面写属性值时没有提示,这里是手工写的,确实容易写错
回复
菜鸟营新兵 2015-08-03
引用 3 楼 qq137510669 的回复:
页面的是u.userMessage.name 后台的是 private UserMessage useraMessage; u.userMessage.name改成u.useraMessage.name,中间少了个字母a
好眼力,这都被你发现了。
回复
qq137510669 2015-08-03
页面的是u.userMessage.name 后台的是 private UserMessage useraMessage; u.userMessage.name改成u.useraMessage.name,中间少了个字母a
回复
qq_29808325 2015-07-30
下面是报错代码
严重: Servlet.service() for servlet jsp threw exception
javax.el.PropertyNotFoundException: Property 'userMessage' not found on type com.aode.jww.model.User
	at javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:266)
	at javax.el.BeanELResolver$BeanProperties.access$300(BeanELResolver.java:243)
	at javax.el.BeanELResolver.property(BeanELResolver.java:353)
	at javax.el.BeanELResolver.getValue(BeanELResolver.java:97)
	at org.apache.jasper.el.JasperELResolver.getValue(JasperELResolver.java:104)
	at org.apache.el.parser.AstValue.getValue(AstValue.java:183)
	at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184)
	at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:967)
	at org.apache.jsp.Admin.list_jsp._jspx_meth_c_005fforEach_005f0(list_jsp.java:166)
	at org.apache.jsp.Admin.list_jsp._jspService(list_jsp.java:109)
	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:748)
	at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:486)
	at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:411)
	at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:338)
	at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:209)
	at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:266)
	at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1225)
	at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1012)
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:876)
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:931)
	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:822)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:807)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:744)
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2015-07-30 10:28
社区公告
暂无公告