[英]using http request parameters in spring mvc
I am generating a table of data from a simple list of objects that I am displaying in a jsp page. 我正在从显示在jsp页面中的简单对象列表中生成数据表。 Each row has a View hyper link attached to it. 每行都附加了一个“视图”超级链接。 When the user clicks on the hyper link I need to send them to another controller (hooked up via a bean) to display more detailed information. 当用户单击超级链接时,我需要将它们发送到另一个控制器(通过Bean挂钩)以显示更多详细信息。 I am trying to pass a unique id but in the controller that handles the request, when I try to retrieve the uniqueId via request.getParameter("uniqueId") it is always null. 我试图传递唯一的ID,但是在处理请求的控制器中,当我尝试通过request.getParameter(“ uniqueId”)检索uniqueId时,它始终为null。
So how should I handle requestParameter's in Spring MVC? 那么我应该如何在Spring MVC中处理requestParameter呢?
Update: 更新:
An example from my jsp: 我的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>
in my servlet configuration, I have: 在我的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>
There are more Spring-specific ways to work with parameters, such as using the @RequestParam annotation, but if getParameter isn't working I wouldn't expect the annotation to work either; 有更多特定于Spring的方法来使用参数,例如使用@RequestParam批注,但是如果getParameter不起作用,我也不希望该批注起作用。 it sounds like the value isn't making it into the request. 听起来好像值没有进入请求。
How are you passing the ID when the user clicks the link? 用户单击链接时如何传递ID? Is it a querystring, or are you using javascript to make a POST request? 它是查询字符串,还是您使用JavaScript发出POST请求? It would help if you gave us some sample code from your JSP. 如果您从JSP中向我们提供了一些示例代码,这将有所帮助。
Updated based on more info: OK, so you're using a querystring. 根据更多信息进行了更新:确定,因此您正在使用查询字符串。 When you click the link, can you see the correct ID in the URL? 当您单击链接时,可以在URL中看到正确的ID吗?
It occurs to me that your param is named batchId
rather than uniqueId
. 它发生,我认为你的参数是一个名为batchId
而非uniqueId
。 So try that instead. 所以试试看。 If it is still null, try request.gatParameterNames()
and list them all to see what has been submitted. 如果仍然为null,请尝试request.gatParameterNames()
并将它们全部列出,以查看已提交的内容。 Also, make sure your form enctype is not multipart. 另外,请确保您的表单enctype不为多部分。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.