Java web application folder structure

javajava-eeprogramming practicesweb-applicationsweb-development

As a beginner to J2EE, I have recently started developing my own project from scratch using the Core of J2EE : Servlets & Jsps.

I could not evaluate whether my project folder structure is right or not.
Here is my project folder structure.
enter image description here

Before asking question, I admit that I could not answer or neither justify if somebody asks me, why this type of folder structure.
The question: Is it a good sign to put my jsps outside of web-inf. If not, why is it so? If yes why?

Is there any standard folder structure convention for a J2EE web application, I know maven has brought up some standards but still, we can customize as per the requirement I believe.

I have done a bit of googling and found the two references
1
2

where in the answers are not on the same page, from which I couldn't draw any conclusion.

What are the points to be considered while laying out the folder structure for a J2EE web application, importantly where should the Jsps, static content should go into & why?

Best Answer

The standard structure for a WAR file is:

/META-INF
   Standard jar stuff like manifest.xml
/WEB-INF
  web.xml
  /classes
    /com...etc.
  /lib

Maven generates this for you using your src/main/java, resources, webapp and your dependencies (placing them in /lib) in the maven-webapp-plugin, but that's implementation. The important thing to realize is that anything you put in WEB-INF is not externally accessible, whereas everything in the root directory of the WAR is public.

Generally you don't want to put much in the root, since you want your application to handle all access using the servlets and filters you define in web.xml. It's common to see an index.html (or .jsp) in the root that redirects to a servlet, for instance a Struts action.

Typical MVC implementations such as Stripes or Struts recommend against user's accessing JSPs directly, preferring that JSPs be view-only. They recommend creating controllers that forward to JSPs after processing the request, and the JSPs merely render the result. For instance, submitting a form to /login will run an action that processes the login request, creates the user's session, and forwards the user to the logged-in view of the home page JSP.