In a servlet mapping in Spring MVC how do I map the root of a url pattern directory?

后端 未结 5 1510
故里飘歌
故里飘歌 2020-12-05 16:28

    testServlet
    /test/*

<         


        
5条回答
  •  无人及你
    2020-12-05 16:50

    my setup usually looks like this:

    
        testServlet
        /
    
    

    controller, where i assume you want to handle /test and /test/ equally:

    @Controller
    public class MyController {
    
        @RequestMapping("/test")
        public String test() {
            return "redirect:/welcome";
        }
    
        @RequestMapping("/test/")
        public String test() {
            return "redirect:/welcome";
        }
    
        @RequestMapping("/welcome")
        public void test(ModelMap model) {
            // do your stuff
        }
    }
    

    setup like this would cause DispatcherServlet to handle requests for *.css and *.js files, which is not desired in most cases. i think this is the problem Bhavik describes. For those resources you can you the ResourceController like this:

    
    
    

    files from /resources/css and /resources/js will be served without forcing you to write a extra controller.

提交回复
热议问题