File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Spring Navigation

Javier Blazquez

Joined: Mar 10, 2012
Posts: 2

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?

I agree. Here's the link:
subject: Spring Navigation
jQuery in Action, 3rd edition