Note that there are some explanatory texts on larger screens.

plurals
  1. POWeb Flow problems from GET Jsp to a POST JSP (Form) - Spring MVC Annotated
    text
    copied!<p>i have a JSP with hyperlink</p> <pre><code>&lt;table&gt; &lt;tr&gt; &lt;td&gt;Product Name : &lt;/td&gt; &lt;td&gt;${product.name}&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Description:&lt;/td&gt; &lt;td&gt;${product.description}&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Price:&lt;/td&gt; &lt;td&gt;${product.price}&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt;&lt;td&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;a href="../shopbasket/populateBasket?code=${product.productCode}&amp;name=${categoryName}"&gt;Add to shopping basket&lt;/a&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt;&lt;td&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;table&gt; &lt;tr&gt; &lt;td&gt;&lt;a href="&lt;c:url value="../index.html"/&gt;"&gt;Return to Home Page&lt;/a&gt;&lt;/td&gt; &lt;td&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/td&gt; &lt;td&gt;&lt;a href="&lt;c:url value="/j_spring_security_logout"/&gt;"&gt;Logout&lt;/a&gt; (&lt;security:authentication property="principal.username" /&gt;) &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/td&gt; &lt;/tr&gt; </code></pre> <p></p> <p> </p> <p>And the controller</p> <p>@Controller @SessionAttributes("basket") public class ShopBasketController {</p> <pre><code>private BasketManager basketManager; private CustomerManager customerManager; private CategoryManager categoryManager; @Autowired public ShopBasketController(BasketManager basketManager, CustomerManager customerManager, CategoryManager categoryManager) { this.basketManager = basketManager; this.customerManager = customerManager; this.categoryManager = categoryManager; } @RequestMapping(value="/basketItems", method=RequestMethod.POST) public String removeProduct(@ModelAttribute("basket") Basket basket, BindingResult bindingResult, Model model) { Basket newBasket = ShoppingBasketUtils.removeFromBasket(basket, basketManager); basketManager.update(newBasket); model.addAttribute("basket",newBasket); model.addAttribute("customer", "Sonx"+" Nkuks"); model.addAttribute("totalItems", basketManager.getTotalNumberOfItems(basket)); model.addAttribute("totalPrice", ShoppingBasketUtils.currencyFormat(basketManager.getTotalProductPrice(basket))); return "basketItems"; } @RequestMapping("/populateBasket") public String populateBasket(@RequestParam("code") String productCode, @RequestParam("name") String categoryName, Model model) { Customer customer = customerManager.getCustomer("Sonx", "Nkuks"); if(customer != null) { Basket shopBasket = ShoppingBasketUtils.addToBasket(productCode, categoryManager.getCategory(categoryName), basketManager.getBasket(customer.getReferenceNumber()), basketManager); basketManager.update(shopBasket); model.addAttribute("basket",shopBasket); model.addAttribute("customer", customer.getFirstName()+" "+customer.getLastName()); model.addAttribute("totalItems", basketManager.getTotalNumberOfItems(shopBasket)); model.addAttribute("totalPrice", ShoppingBasketUtils.currencyFormat(basketManager.getTotalProductPrice(shopBasket))); return "basketItems"; } model.addAttribute("customer", "test".concat(" test")); return "/error"; } </code></pre> <p>}</p> <p>Then the form ...</p> <pre><code>&lt;form:form commandName="basket"&gt; &lt;table&gt; &lt;tr&gt; &lt;td&gt; &lt;table&gt; &lt;tr&gt; &lt;td&gt;Customer Name : &lt;/td&gt; &lt;td&gt;${customer}&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;table width="600" border="1" cellspacing="0" cellpadding="2" border="0"&gt; &lt;thead&gt; &lt;tr&gt; &lt;td&gt;Products:&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Product Name&lt;/td&gt; &lt;td&gt;Product Code&lt;/td&gt; &lt;td&gt;Description&lt;/td&gt; &lt;td&gt;Price&lt;/td&gt; &lt;td&gt;Remove&lt;/td&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;c:forEach items="${basket.products}" var="product"&gt; &lt;tr&gt; &lt;td&gt;${product.name}&lt;/td&gt; &lt;td&gt;${product.productCode}&lt;/td&gt; &lt;td&gt;${product.description}&lt;/td&gt; &lt;td&gt;${product.price}&lt;/td&gt; &lt;td&gt;&lt;form:checkbox path="removeItemCodes" value="${product.productCode}" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/c:forEach&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;table&gt; &lt;tr&gt; &lt;td&gt;Total Price&lt;/td&gt; &lt;td&gt;&amp;nbsp;&lt;/td&gt; &lt;td&gt;${totalPrice}&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Total Items&lt;/td&gt; &lt;td&gt;&amp;nbsp;&lt;/td&gt; &lt;td&gt;${totalItems}&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt;&lt;td&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;input type="submit" value="Remove Items" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt;&lt;td&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;table&gt; &lt;tr&gt; &lt;td&gt;&lt;a href="&lt;c:url value="../index.html"/&gt;"&gt;Return to Home Page&lt;/a&gt;&lt;/td&gt; &lt;td&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/td&gt; &lt;td&gt;&lt;a href="&lt;c:url value="/j_spring_security_logout"/&gt;"&gt;Logout&lt;/a&gt; (&lt;security:authentication property="principal.username" /&gt;) &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; </code></pre> <p></p> <p>When i press the link from the first JSP "" the controller succesfully execute the method populateBasket and loads the Form. But when i submit the form, i want it to call the POST method (basketItems)... But it doesn't, pressng the submit button always executes the GET method (populateBasket) .. This doesn't happen if i load the form directly from the index page, it loads successfully . Problem is when coming from that JSP ?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload