Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

folder structure of jsp's?

Tags:

java

jsp

maven

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

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.

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?

like image 729
user2883880 Avatar asked Jan 03 '14 04:01

user2883880


People also ask

What is the typical directory structure of JSP web application?

Below is the typical directory structure JSP Web Application Root Directory – This is the main or Root folder of web application. Usually name of this folder becomes your web application context.

What is the directory name of JSP-tutorial?

For example, if our web application name is jsp-tutorial , then folder name will be jsp-tutorial and web application will be accessible via http://localhost:8080/jsp-tutorial /jsp page. WEB-INF- This is the special directory under web application root directory.

What is the root directory of a JSP application?

JSP Web Application Root Directory – This is the main or Root folder of web application. Usually name of this folder becomes your web application context. For example, if our web application name is jsp-tutorial , then folder name will be jsp-tutorial and web application will be accessible via http://localhost:8080/jsp-tutorial /jsp page.

Where do I put JSP files in Eclipse?

JSP File – All JSP files can be placed directly inside a root directory or inside sub folders of WEB-INF folder. When placed inside WEB-INF or its sub folders, jsp can not be accessed directly. While working with eclipse, we create the JSP files inside WebContent directory.


1 Answers

All I can do is tell you the pros and cons to specific ideas. What follows is 100% my opinion. I don't know of any specific requirements or rules. I'm sure somebody will disagree with me.

JSP's

Let's work on whether to put JSP's in WEB-INF or not.

Pros of putting JSP's in WEB-INF:

  • You control how the JSP's are executed. If you want a JSP to be parameterized and re-usable (which is really hard with a JSP anyway), you can put them into WEB-INF and use a servlet or a Struts action controller or some other front controller to do pre-processing and then pass control to the JSP, passing in the right environment context (like request attributes, any security checks, parameter sanitation, etc.)

  • You can programmatically or even at a firewall or IDS level block
    HTTP requests to *.jsp to reduce the likelihood of somebody uploading a JSP to the web root and then being able to execute code as the web server. They'd have to over-write an existing JSP. Not a huge
    security gain, but it does make compromise slightly harder.

  • Enforces good habits, like MVC, front controller, servlet filters,
    dependency injection, etc. as opposed to a big monstrous JSP that
    does all the work itself and is difficult to read/maintain.

Cons of putting JSP's in WEB-INF:

  • You cannot access the page directly, even if it is a simple standalone page which needs no upfront processing. This is because files under /WEB-INF are not servable by a servlet container.

Static files In terms of purely static files like HTML, image, stylesheet, javascript, etc. put those under the web root (my_app in your case), but NOT /WEB-INF (because it is not accessible).

Overall layout

As for the overall directory layout, it depends somewhat on your build process. I like storing everything under "src" or "source" because it makes it clear what files are generated by building and which are pure source files. main lets you separate test code like junit classes from your main source code, which is good too. But if you don't have any unit tests (oh no!), then it's a meaningless distinction.

On the other hand, if you don't manipulate the web root at all during build (like if it's all JSP and static files), then perhaps you keep it at the top level, like /webroot or /deploy and copy files in as needed, such as .class or .jar files. It is a habit of human beings (especially developers) to over-organize. A good sign of over-organizing is having lots of folders with only a single sub-folder.

What You've Shown

You've indicated that you are following a convention set by maven, so if you are already using maven, just stick with that layout. There is absolutely nothing wrong with the layout you described.

like image 125
3bu1 Avatar answered Oct 16 '22 23:10

3bu1