What is the best practice of the directory Structure Of Java Web Application

1.1k Views Asked by At

For the WEB-INF folder, it will only store the files that are not accessible to the public. So it will be only index.html stay outside of the WEB-INF folder? For example, like the login and register jsp file should stay inside or outside the WEB-INF folder?

1

There are 1 best solutions below

2
JRichardsz On

As you said, the WEB-INF content will not be accessible when the web is deployed. Commonly this folder store web low level settings. Also when the app is deployed (classic war on tomcat) this folder WEB-INF has a folder called lib with all the jar libraries.

Any other static asset like, html, css, font, js, etc should be outside of WEB-INF

Just the dynamic content like .jsp should be inside of WEB-INF

Take a look to this maven structure:

enter image description here

or this in which we can see the classic web.xml

enter image description here

or this with spring-boot

./pom.xml
./src
./src/main
./src/main/webapp
./src/main/webapp/WEB-INF
./src/main/webapp/WEB-INF/jsp
./src/main/webapp/WEB-INF/jsp/hello.jsp
./src/main/resources
./src/main/resources/application.properties
./src/main/java
./src/main/java/com
./src/main/java/com/
./src/main/java/com/examples
./src/main/java/com/examples/spring
./src/main/java/com/examples/spring/springbootjsp
./src/main/java/com/examples/spring/springbootjsp/controllers
./src/main/java/com/examples/spring/springbootjsp/controllers/HelloController.java
./src/main/java/com/examples/spring/springbootjsp/SpringBootJspApplication.java

I advice you:

  • Use a maven structure for your java web app
  • Use spring