GeeCON Prague 2014*
The moose likes Spring and the fly likes Spring Navigation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Spring Navigation" Watch "Spring Navigation" New topic
Author

Spring Navigation

Javier Blazquez
Greenhorn

Joined: Mar 10, 2012
Posts: 2
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Spring Navigation