java - 如何通过 requestscope 获取对象内部对象的值?
问题描述
我在一个大类对象中有许多类对象的子对象。我已经为这些子对象设置了值,我希望它们通过请求范围打印在我的 jsp 页面中。我如何在jsp中实现这个?
我的大类对象
public class BookUser implements Serializable {
private Books book;
private Users user;
public BookUser() {
}
public Books getBook() {
return book;
}
public void setBook(Books book) {
this.book = book;
}
public Users getUser() {
return user;
}
public void setUser(Users user) {
this.user = user;
}
}
我的jsp
<c:set var="listBookNew" value="${requestScope.LISTALLBOOKORIGINAL}"/>
<c:if test="${not empty listBookNew}">
<table border="1">
<thead>
<tr>
<th>Id</th>
<th>Title</th>
<th>Price</th>
<th>Quantity</th>
<th>Date</th>
</tr>
</thead>
<tbody>
<c:forEach var="dtoX" items="${listBookNew}">
<tr>
<td>${dtoX.book.id}</td>
<td>${dtoX.book.bookTitle}</td>
<td>${dtoX.book.price}</td>
<td>${dtoX.book.quantity}</td>
<td>${dtoX.book.bookDate}</td>
</tr>
</c:forEach>
</tbody>
</table>
</c:if>
编辑:我输入了我的 requestscope 属性名称错误。对不起大家,感谢大家花时间阅读本文。
解决方案
您可以在 forEach 和 tr 之间添加 c:set ,如下所示:
<c:forEach var="dtoX" items="${listBookNew}">
<c:set var="book" value="${dtoX.book}"/>
<c:set var="user" value="${dtoX.user}"/>
<tr>
<td>${book.id}</td>
<td>${book.bookTitle}</td>
<td>${book.price}</td>
<td>${book.quantity}</td>
<td>${book.bookDate}</td>
</tr>
<tr>
<td>${user.id}</td>
...
</tr>
</c:forEach>
推荐阅读
- javascript - 我该如何解决?DOM javascript渐变不起作用?
- android - Flutter:如何使用 Navigator PushNamed 为 Screen Constructor 发送所需的参数
- css - 相对于列表中第 n 个位置的动画延迟
- entity-framework - Xamarin Forms Android EnsureCreated 的实体框架核心无法正常工作
- python - 如何避免 cv2.undistort 造成的延迟?
- python - python中使用pickle的基于类的字典
- delphi - Delphi如何加载存储在数据库中的报告
- java - Intelli IDEA 没有启动 32bit 安装的 jvm.dll
- python-3.x - 为什么 Python 的模块 os 不运行 chromehtml2pdf 命令?
- python - vs中的python问题