JSP application directory structure review

zhaozj2021-02-16  101

Review the directory structure of a simple JSP program

For the client, the JSP program directory includes two parts: public directory and invisible directory (web-inf).

The basic web app directory has a good directory structure, like a well-organized Classes Package, will make people look very comfortable. It is important that it makes you maintain it, and let others understand your app.

We can take a look at the directory structure root / index.html / travel / products.jsp / travel / tickets / query.jsp / help / howto.jsp / help / faq.html / images / *. GIF is put What is the way in the root directory?

Web-INF In every JSP application directory, we can see a web-inf directory, which is invisible for the client. We can save information that does not want to disclose it. Generally: /Web-inf/web.xml saves the configuration information of the application; / Web-inf / class saves some servlets and utility classes; / web-inf / lib / can put some JAR files. In our program, we can access these files saved under Web-INF via servletContext.getResource and servletContext.getResourceAsStream.

Add some point: In Serverspecification 2.4, Web Container (Tomcat, WebLogic, etc.) Must first load the application from the CLASSES directory, and then load the JAR file from lib. Any access to / web-inf / down resources, Web Container must return a 404 Error.

What will further affect our web application? We all know that you can configure servlet mappings that determine which servlet class of the URL of the user requests from the element in Web.xml. In the mapping configuration, the designation of is actually related to our directory structure. Let's take a look at the example below. In the configuration file, we wrote: servlet1 / travel / tickets / * < servlet-mapping> servlet2 / travel / * When the user entered: / travel / a, the servlet Will deal with it? The Web Container is found in a full match-> URL PATH match-> extension matching method. Therefore, servlet2 will be called.

Therefore, everyone should take some time to consider the application's directory structure when considering the application.

转载请注明原文地址:https://www.9cbs.com/read-11284.html

New Post(0)