Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Spring Navigation  RSS feed

Javier Blazquez
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I'm developing a web project based on Spring and Struts. One of my web pages consist on add products to a shopping cart but I want to have the product lists and shopping cart in the same page that will be populate every time I click on a hiperlink.

The problem that i'm facing is that I am not be able to redirect to the same page. I have one CartController with two actions:

public ModelMap doHome() {
ModelMap model = new ModelMap();
model.addAttribute("shoppingCart", cartManager.getShoppingCart());
model.addAttribute("products", cartManager.getProducts());
return model;

public ModelAndView addToCart(@RequestParam("productId") int productId){

Product product = cartManager.getProduct(productId);

ModelAndView mav = new ModelAndView(new RedirectView("/addT.html"));
mav.addObject("products", cartManager.getProducts());
return mav;

The first method loads my product list and the second add to the cart. Both of them should go to the same jsp page. To triggering the seconda action I have the following tag in my jsp page:

<a class="banner-link fright" href="${contextPath}/addT.html?productId=${}">[add to cart]</a>

I have tried almos everything, return redirect:xxxxx, new RedirecView, but when I click on my hyperlink springs asking me about addToCart.jsp that obviously I don't have (what I want is to redirect to a addT.jsp). It is as if it would be the same what i write on modelandview, always try to go to the action that I write on the jsp.

Could you help me to resolve this issue?

It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!