Reputation: 159
Suppose I have a list of objects in a Spring web application view. Suppose these objects are forum threads. Each of them has a link, which will move to the page with all topics for this thread. Now in order to list those topics, I will need to retain the thread id which was selected. Part of the .jsp that contains the link:
<h3><spring:message code="label.threadList"/></h3>
<c:if test="${!empty threadList}">
<table class="data">
<tr>
<th><spring:message code="label.threadName"/></th>
<th><spring:message code="label.threadDescription"/></th>
<th><spring:message code="label.threadTopicCount"/></th>
<th><spring:message code="label.threadLastModified"/></th>
<th>Go</th>
</tr>
<c:forEach items="${threadList}" var="thread">
<tr>
<td>${thread.name} </td>
<td>${thread.description} </td>
<td>${thread.topics}</td>
<td>${thread.last_modified}</td>
<td><a href="topics.html">Open</a></td>
</tr>
</c:forEach>
</table>
Now, from what I understand, I will need to take the param by request mapping:
@Controller
public class TopicPageController {
@RequestMapping(value = "/topics", method = RequestMethod.GET)
public ModelAndView helloWorld(@RequestParam("getId") int getId) {
System.out.println(getId); //here's when I want to see the param
return new ModelAndView();
}
}
What I can't get right, is passing it. How can I include, that on clicking this link, the request will get that parameter?
Upvotes: 4
Views: 9510
Reputation: 3549
Add the id to the link:
<td><a href="topics.html?getId=${thread.id}">Open</a></td>
Upvotes: 4