Why put the .jsp file in the WEB-INF directory?

6

Taking Maven as an example, when started a new web project, the structure is the same / similar to this:

Meu Projeto
    |- src
        |- main
            |- java
            |- resources
            |- webapp
                 |- WEB-INF

Where, in the "webapp" directory are placed the files used by the web application: html, css, Javascript, JSPs, etc.

My question is in relation to the WEB-INF directory, there are several projects that use this directory to put files with .jsp extension, instead of placing them directly in "webapp". An example is Caelum's Mammoth , where they created a directory called "jsps" for this.

As I read about it, the files contained in WEB-INF can not be accessed directly by the client because they are not public, but can be accessed by servlets:

  

A special directory exists within the hierarchy named WEB-INF. This directory contains all things related to the application that is not in the root document of the application. The WEB-INF node is not part of the public document tree of the application. No file contained in the WEB-INF directory may be served directly to a client by the container . However, the contents of the WEB-INF directory are visible to the servlet code using the getResource and getResourceAsStream method calls on the ServletContext , and may be exposed using the RequestDispatcher calls .

So it would only be for safety? The only way to get the files would be when being processed through a servlet.

    
asked by anonymous 02.04.2016 / 00:14

1 answer

2

9.10 Hiding our pages - link

If the pages stay in / webapp, the user will have direct access to them. If it's just static pages, I see no problem. But some pages need a logic before they are displayed, if the user accesses the jsp directly the page will not be displayed correctly, it will not go through the controller.

"

"

    
25.04.2016 / 02:09