Java 显示单击的特定链接的数据
我正在创建一个spring mvc estore web应用程序。这里有一个名为showproducts.jsp的jsp页面将数据库中的所有产品呈现在一个表中。这里有一个名为Additional info的列Java 显示单击的特定链接的数据,java,spring,jsp,spring-mvc,Java,Spring,Jsp,Spring Mvc,我正在创建一个spring mvc estore web应用程序。这里有一个名为showproducts.jsp的jsp页面将数据库中的所有产品呈现在一个表中。这里有一个名为Additional info的列 <table class="table table-striped table-hover"> <thead> <tr class="bg-success"> <th>Product Name&
<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.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>
当然,您需要实现一个从数据库中获取实体的方法
希望有帮助 谢谢您提供的解决方案。它可以按需要工作。@控制器中的RequestParam也被添加,用于向DAO层提供id。