Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why put JSP in WEB-INF?

Tags:

java

jsp

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?

like image 946
Konrad Garus Avatar asked Jul 26 '11 06:07

Konrad Garus


People also ask

What should be in the web-INF folder?

WEB-INF. This directory, which is contained within the Document Root, is invisible from the web container. It contains all resources needed to run the application, from Java classes, to JAR files and libraries, to other supporting files that the developer does not want a web user to access.

Where should I put JSP files?

In order to deploy Java Server Pages (JSP) files, you must place them in the root (or in a subdirectory below the root) of a Web application.

Why we use JSP over HTML?

JSP provides a dynamic interface for the continuously changing data and also it dynamically invokes the server actions. HTML provides a means to give a detailed account of the structure of text-based information in a document. JSP generated dynamic web pages only. Whereas Html generated static web pages only.

What is the purpose of using JSP?

JavaServer Pages (JSP) is a technology for developing Webpages that supports dynamic content. This helps developers insert java code in HTML pages by making use of special JSP tags, most of which start with <% and end with %>.


1 Answers

Files in WEB-INF are not visible to the users. It's a bit safer that way.

If (a contrived example) you are including db.jsp, but by itself it throws an exception, a malicious user can open http://yoursite.com/db.jsp and get some insight on your application (worst - the database credentials) from the exception message.

like image 114
Bozho Avatar answered Oct 24 '22 13:10

Bozho