开发者

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. Each row has a View hyper link attached to it. When the user clicks on the hyper lin开发者_C百科k I need to send them to another controller (hooked up via a bean) to display more detailed information. 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.

So how should I handle requestParameter's in Spring MVC?

Update:

An example from my 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:

<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>


It occurs to me that your param is named batchId rather than uniqueId. So try that instead. If it is still null, try request.gatParameterNames() and list them all to see what has been submitted. Also, make sure your form enctype is not multipart.


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; it sounds like the value isn't making it into the request.

How are you passing the ID when the user clicks the link? Is it a querystring, or are you using javascript to make a POST request? It would help if you gave us some sample code from your 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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜