[] Servlet Servlet configuration

Created: 6.15

 

Servlet configuration

1. basic configuration

 

Wherein the url-pattern configuration:

1) exact match exactly the same access to resources and configuration of access to resources

2) directory matches the format: / virtual directory ../* * represents any that access any resources in this virtual directory can access to this stuff


 

The browser address

 

Have access to

 

3) extension matches the format: * extension.

 

 

The browser address:

 

 

! Note: The second and third do not mix / aaa / bbb / * abcd (wrong).

 

2. Servlet instance of the server startup configuration

Servlet when to create: default create first visit servlet

 

Why is the default? You can modify created when the server is started:

When coupled with a configuration when you configure the web.xml servlet <load-on-startup> servlet object is created when the server starts

(Typically accounting for the number of middle priority)

 

 

 

 

3. Default Servlet

url-pattern may be configured a /, on behalf of the servlet is the default servlet

 

 

 

 

What is the default (default) in the servlet?

When you access a resource addresses of all the servlet does not match (not the resource), the default servlet handles

 

 

* In fact, web applications to respond to all of the resources are responsible for servlet, including static resources

 

(Servlet is the default configuration, less than the static resource access.)

 

Example: Create a html, the html file access, display is service () print content

 

 

 

 

Want to access static resources, prior written three kinds url-patteern configuration on the line.

 

the reason:

 

* First mention of the global Tomcat configuration file:

 

Here web.xml Tomcat is global and applies to all items in the Tomcat web, but when the number of items and web.xml internal configuration conflicts, it is effective to partially project within web.xml

 

 

* Let me say is how to find internal resources.

 

* Internal resources to find the process:

不是直接找文件。内部将名称1.html整体作为名称,去web项目中的配置文件web.xml中找资源<url-pattern>1.html</url-pattern>,(动态资源找不到)没有找到就去找Tomcat全局配置文件web.xml中的<url-pattern>/</url-pattern>,它去找DefaultServlet。

 

DefaultServlet去Web项目下找有没有一个叫1.html的静态资源,找到就逐行输出,没有就报404(404也是页面,是DefaultServlet在没有找到资源时提供的)

 

 

 

 

  •   正文:如果在一个web项目的配置文件里写<url-pattern>/</url-pattern>,它找的本项目的DefaultServlet,然而它并没有返回静态资源的功能!

 

 

 

4.欢迎页面

 

页面访问时什么都不写,web.xml中这么一段话,第一个是index.xml,找到了就不会再往下找,所以当同时有1.html和index.html时,生效的是index文件

 

 

想要1.html为首要生效,就在这段话里加一句:

 

*如果删除了整段话,页面仍然默认显示index。

为什么?

因为Tomcat的全局web.xml里也有这样一段话

 

Guess you like

Origin www.cnblogs.com/musecho/p/11201752.html