Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Spring Navigation

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

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:

@RequestMapping("/addT.html")
public ModelMap doHome() {
ModelMap model = new ModelMap();
model.addAttribute("shoppingCart", cartManager.getShoppingCart());
model.addAttribute("products", cartManager.getProducts());
return model;
}

@RequestMapping("/addToCart.html")
public ModelAndView addToCart(@RequestParam("productId") int productId){


Product product = cartManager.getProduct(productId);
shoppingCart.addItem(product);

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=${product.id}">[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?

Thanks,
JB
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic