Spring - Display multiple URLs

I asked a few days ago about this, but now a new problem has appeared. My web page needs to access these URLs:

/product/* //(this will be an id or anything else)
/shopcart/* //(GET, ADD...)
/*.html

I need to access various HTML pages to get web server information. In webapp you can request some products idand you can see a detailed web page with all its specifications. In addition, I have a shopping basket where you can add products, and every time you add a product, it will be saved in a server session.

If I want to restore product information in the basket, I get access to /shopcart/getand get all the information in JSON format. I have this config in my web.xml for this:

<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>

, /product/1, 1, , /shopcart/1. @RequestMapping("product") (,) , /product/product/1, . ?

:

@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);
    }
}
+3
1

soluiton .

, RC . , URL-, servlet-mapping web.xml :

<servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

, :

@Controller
@RequestMapping("product")
public class ProductController {

    @RequestMapping("{id}")
    public ModelAndView get(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, @PathVariable String id) {
        ...
    }

@Controller
@RequestMapping("shopcart")
public class CartController {

    @Autowired
    private JacksonConverter JacksonConverter;

    @RequestMapping(value = "get", method = RequestMethod.GET)
    public void get(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
        ...
    }

, . CSS JS. , Spring , (dispatcher-servlet.xml ):

<mvc:resources mapping="/resources/**" location="/resources/"/>

URL- /resources , . JSP-, :

<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/resources/css/main.css">
<script type="text/javascript" src="${pageContext.request.contextPath}/resources/js/main.js"></script>

: Spring css

. CSS JS , /resources/css /resources/js, , - .

+3

All Articles