Directory structure of the Web application

Source: Internet
Author: User

A Web application basically consists of the following items:

1. Static resources (HTML,CSS, pictures, sounds, etc.)

2.Servlet

3.JSP

4. Custom Classes

5. Tool Class

6. Deployment profile (Web. XML, etc.), setup information (annotation, etc.)

The Web application directory structure must conform to the specification. For example, if the environment path for an application is/helloservlet, all resource items must be placed in/helloservlet as the root directory according to the specified structure. Basically the resources in the root directory can be downloaded directly, if Index.html is located under/helloservlet, it can be obtained directly with/helloservlet/index.html.

A special/web-inf subdirectory exists in the WEB application, and the resources present in this directory are not listed as items that are directly accessible in the application root directory. That is, the client (such as browser) can not directly request resources in the/web-inf (directly on the URL to indicate access to/web-inf), otherwise 404 Not Found error results. The resource project in/web-inf has a certain name and structure.

(1)/web-inf/web.xml is a deployment profile

(2)/web-inf/classes the custom class (. Class) used to place the application, you must include the package structure.

(3)/web-inf/lib is used to place the jar file used by the application.

The jar file used by the Web application, where you can place Servlets, JSPs, custom classes, tool classes, deployment profiles, and so on, and the application's class loader can load the corresponding resources from the jar.

You can place static resources or JSPs in the/meta-inf/resources directory in the jar file, for example, if you put a index.html in/meta-inf, and if you include/helloservlet/index.html in the requested URL, you actually Index.html is not present in the/helloservlet root directory, the/meta-inf/resources/index.html in the jar is used.

If a class is to be used, the WEB application tries to load the class into the/web-inf/classes, and, if none, tries to find the class file from the/web-inf/lib jar file (if it is not found yet, it looks in the directory where the container implementation itself holds the class or jar, But the location is different depending on the implementation of the manufacturer, in Tomcat, for example, the search path is the Lib directory in Tomcat's installation directory.

The client cannot directly request resources in the/web-inf, but can be controlled by the program to get the resources in/web-inf, such as using ServletContext's GetResource () and getResourceAsStream (), or by RequestDispatcher request.

Web App Default home page settings: Access URL such as: localhost:8080/firstservlet/

<welcome-file-list>

<welcome-file>index.html</welcome-file>

<welcome-file>default.jsp</welcome-file>

</welcome-file-list>

If the above file is not found, it will attempt to find the placed resource page in the jar's/meta-inf/resources.

The entire Web application can be encapsulated as a war file, such as Firstservlet.war, to facilitate deployment to the Web container.

Directory structure of the Web application

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.