Am new to Spring Web MVC and developing a web application. There is a case where i need to pass a data value to Controller. (Note: Here the data value is a value of bean object )
Item Number Item Name Description Price
Item1018 Item1 Desc1 5.0 Add item to Cart
Item1019 Item2 Desc2 2.0 Add item to Cart
As shown in above image, if i click on "Add item to Cart" the respective item number should be passed to controller.
viewmenu.jsp
<c:forEach items="${model.itemlists}" var="item">
<tr>
<c:if test = "${item.status == 'available'}">
<td><c:out value="${item.itemNo}"/> </td>
<td><c:out value="${item.itemName}"/></td>
<td><c:out value="${item.description}"/></td>
<td><c:out value="${item.price}"/></td>
<td><a href="<c:url value="additemtocart">
<c:param name='itemNumber' value="${item.itemNo}"/>
</c:url>">Add item to Cart</a> </td>
</c:if>
</tr>
</c:forEach>
CustomerController.java method
@RequestMapping(value = "additemtocart",method = RequestMethod.GET)
public ModelAndView addItemToCart(@RequestParam("itemNumber") String itemno ) throws ClassNotFoundException, SQLException {
System.out.println("Username test in customer controller: "+userName);
}
The code works and am able to pass the value. But as per standards of GET and POST methods (described here ), i think am doing wrong. Please suggest is there any other way to pass the data in to the POST method. Please suggest me. Thanks in advance
(This is first time am posting here, excuse me if there are any mistakes )