我正在从 jsp 页面中显示的简单对象列表生成数据表。每行都附有一个“查看”超链接。当用户单击超链接时,我需要将它们发送到另一个 Controller (通过 bean 连接)以显示更详细的信息。我试图传递一个唯一的 id,但在处理请求的 Controller 中,当我尝试通过 request.getParameter("uniqueId") 检索 uniqueId 时,它始终为 null。
那么我应该如何在 Spring MVC 中处理 requestParameter?
更新:
来 self 的 jsp 的示例:
<c:forEach var="file" items="${confirmationFiles}">
<tr>
<td>${file.batchId}</td>
<td>${file.runDate}</td>
<td>${file.customerId}</td>
<td>${file.userName}</td>
<td><a href="view-detail.do?batchId=${file.batchId}">View</a></td>
</tr>
</c:forEach>
在我的 servlet 配置中,我有:
<bean name="/view-detail.do"
class="ViewDetailController">
</bean>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
最佳答案
我发现您的参数名为 batchId
而不是 uniqueId
。所以尝试一下吧。如果仍然为 null,请尝试 request.gatParameterNames()
并列出所有内容以查看已提交的内容。另外,请确保您的表单 enctype 不是多部分的。
关于java - 在spring mvc中使用http请求参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2374382/