Why put JSP in WEB-INF?

后端 未结 3 1059
死守一世寂寞
死守一世寂寞 2020-11-28 11:44

I noticed a common pattern is to put JSP pages in WEB-INF folder (as opposed to WAR root). What\'s the difference? Why is that preferred?

3条回答
  •  情歌与酒
    2020-11-28 12:26

    An extra-plus when using a Controller (or Front-Servlet) is that you decouple the URL path from the physical location of the JSP-files in your project.

    As example here a simple request-mapping from a Spring Controller:

    @RequestMapping(value = "/item/edit", method = RequestMethod.GET)
    public String getItemEdit(@RequestParam(value = "id", required = false) final String id) {
        return "itemeditform";
    }
    

    The ViewResolver takes care of mapping the URL to the place where your JSPs reside.

提交回复
热议问题