views:

588

answers:

2

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 link 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>
+1  A: 

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?

JacobM
Yeah, I'm not currently using annotations. I will update my question.
Casey
You were right, the request parameter was never being set.
Casey
+1  A: 

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.

Bozho
Sorry, that was a mistype on my part entering it in SO.
Casey