I've asked something few days ago about this, but now came a new problem. My webpage need to access to these urls:
/product/* //(this will be an id or anything else)
/shopcart/* //(GET, ADD...)
/*.html
I have to access to different HTML pages for some webapp information. At the webapp, you can ask for some products by id and you can see a detailed webpage with all his specs. Also, I have a shopping cart where you can add the products and each time you add a product it will be saved at server's session.
If I want to recover information about products in cart, I access to /shopcart/get and get all information into JSON format. I have this config into my web.xml for that:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/product/*</url-pattern>
<url-pattern>/shopcart/*</url-pattern>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
The problem comes that I can access to /product/1 to get all specs from product 1, but I get the same if I use /shopcart/1. If I specify @RequestMapping("product") (e.g.) into my controller I will have to access to /product/product/1 and I don't want that. How can I resolve this problem?
These are my controllers:
@Controller
public class ProductController {
@RequestMapping("{id}")
public ModelAndView get(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, @PathVariable String id) {
Map<String, Object> model = new HashMap<String, Object>();
//data recovering
return new ModelAndView("product", model);
}
}
@Controller
public class CartController {
@Autowired
private JacksonConverter JacksonConverter;
@RequestMapping(value = "/shopcart/get", method = RequestMethod.GET)
public void get(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
// data recovering
httpServletResponse.setContentType("application/json; charset=utf-8");
httpServletResponse.setStatus(HttpServletResponse.SC_OK);
httpServletResponse.getWriter().print(json);
}
}
/and use annotations to map each controller/methods to their url(s)WEB-INF