我正在创建一个 spring mvc estore Web 应用程序。此处名为“showproducts.jsp”的 jsp 页面在表中呈现数据库中的所有产品。此处有一列名为“附加信息”。
<table class="table table-striped table-hover">
<thead>
<tr class="bg-success">
<th>Product Name</th>
<th>Info</th>
</tr>
</thead>
<c:forEach var="product" items="${products}">
<tr>
<td>${product.productname}</td>
<td><a href="${pageContext.request.contextPath}/pdtdetails">Additional info</a></td>
</tr>
</c:forEach>
</table>
我希望特定产品的 href 转到“pdtdetails”页面,并且单击时仅显示此特定产品的所有详细信息。我在“pdtdetails.txt”中使用以下代码。 jsp”,但正如预期的那样,它显示所有产品的详细信息及其各自的数据,而不是唯一点击的产品。
<c:forEach var="product" items="${products}">
<tr>
productname:${product.productname}<br>
manufacturer:${product.manufacturer}<br>
category:${product.category}<br>
description:${product.description}<br>
units:${product.units}<br>
price:${product.price}<br>
</tr>
</c:forEach>
我应该如何表现出这种行为?
感谢您的宝贵时间。
最佳答案
你可以这样做:
<table class="table table-striped table-hover">
<thead>
<tr class="bg-success">
<th>Product Name</th>
<th>Info</th>
</tr>
</thead>
<tbody>
<c:forEach var="product" items="${products}">
<tr>
<td>${product.productname}</td>
<td><a href="${pageContext.request.contextPath}/pdtdetails?id=${product.id}">Additional info</a></td>
</tr>
</c:forEach>
</tobdy>
</table>
然后在详细信息页面中,从查询参数中获取所选项目并仅显示它:
<c:out value="${param['id']}"></c:out>
当然,您需要实现一个方法来从数据库中获取实体。
希望对你有帮助!
关于java - 显示点击的特定链接的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45092078/