What is WEB-INF used for in a Java EE web application?
The Servlet 2.4 specification says this about WEB-INF (page 70):
A special directory exists within the application hierarchy named
WEB-INF
. This directory contains all things related to the
application that aren’t in the document root of the application. The
WEB-INF
node is not part of the public document tree of the
application. No file contained in theWEB-INF
directory may be served
directly to a client by the container. However, the contents of the
WEB-INF
directory are visible to servlet code using thegetResource
andgetResourceAsStream
method calls on theServletContext
, and may
be exposed using theRequestDispatcher
calls.
This means that WEB-INF
resources are accessible to the resource loader of your Web-Application and not directly visible for the public.
This is why a lot of projects put their resources like JSP files, JARs/libraries and their own class files or property files or any other sensitive information in the WEB-INF
folder. Otherwise they would be accessible by using a simple static URL (usefull to load CSS or Javascript for instance).
Your JSP files can be anywhere though from a technical perspective. For instance in Spring you can configure them to be in WEB-INF
explicitly:
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/"
p:suffix=".jsp" >
</bean>
The WEB-INF/classes
and WEB-INF/lib
folders mentioned in Wikipedia's WAR files article are examples of folders required by the Servlet specification at runtime.
It is important to make the difference between the structure of a project and the structure of the resulting WAR file.
The structure of the project will in some cases partially reflect the structure of the WAR file (for static resources such as JSP files or HTML and JavaScript files, but this is not always the case.
The transition from the project structure into the resulting WAR file is done by a build process.
While you are usually free to design your own build process, nowadays most people will use a standardized approach such as Apache Maven. Among other things Maven defines defaults for which resources in the project structure map to what resources in the resulting artifact (the resulting artifact is the WAR file in this case). In some cases the mapping consists of a plain copy process in other cases the mapping process includes a transformation, such as filtering or compiling and others.
One example: The WEB-INF/classes
folder will later contain all compiled java classes and resources (src/main/java
and src/main/resources
) that need to be loaded by the Classloader to start the application.
Another example: The WEB-INF/lib
folder will later contain all jar files needed by the application. In a maven project the dependencies are managed for you and maven automatically copies the needed jar files to the WEB-INF/lib
folder for you. That explains why you don't have a lib
folder in a maven project.
What does WEB-INF stand for in a Java EE web application?
As far as I know, "INF" stands for "Information", as you said. It probably was named WEB-INF
for similarity with the META-INF
directory in JAR files. Sometimes the meaning of a directory changes so much over time that it no longer makes sense. For example, bin
directories in Unix/Linux often contain non-binary "executable" files, such as shell scripts.
What difference between app-inf and web-inf folders in JavaEE applications?
APP-INF
In an enterprise application (EAR application) which contains many war and jars (eg.WebApp1.war, WebApp2.war, EJB1.jar and EJB2.jar.) and suppose all these Modules want to use some classes which is available as part of a Jar (common.jar). So in this case it is better to Place this jar file inside under “APP-INF” directory,that why we don't need to put the same Jar 4 times inside each and every Modules.
WEB-INF
WEB-INF is a directory that is a private area of the web application, any files under WEB-INF directory cannot be accessed directly from browser by specifying the URL.
See EAR application structure;
use of xml files inside WEB-INF under Web Pages folder
Yes the sun-web.xml
file is for glassfish server.This file for specifying additional web app (WAR) configuration in Glassfish server.Now-a-days sun-web.xml
file is known as glassfish-web.xml
. Get More
And about the weblogic.xml
file is the deployment descriptor for Weblogic Server.If your Web application does not contain a weblogic.xml deployment descriptor, WebLogic Server automatically selects the default values of the deployment descriptor elements. Get more on Weblogic.xml
Related Topics
Most Simple Code to Populate Jtable from Resultset
Java: Define Terms Initialization, Declaration and Assignment
Illegalmonitorstateexception on Wait() Call
Avoid Jackson Serialization on Non Fetched Lazy Objects
Round Up to 2 Decimal Places in Java
Jar Bundler Using Osxadapter Causing Application to Lag or Terminate
How to Kill a Thread? Without Using Stop();
How to Compile Simple Java 10/Java 11 Project with Maven
Float and Double Datatype in Java
Why Does Integer Division Code Give the Wrong Answer
Java Maximum Memory on Windows Xp
How to Gracefully Handle the Sigkill Signal in Java
How to Call the Default Deserializer from a Custom Deserializer in Jackson
Java Wait Cursor Display Problem
What Is the Correct Way to Structure This Kind of Data in Firestore