web development (iv) expansion: global web.xml file in tomcat

File folder for each project web-> there is a web.xml file under WEB-INF. This document is for each project its own unique of.

And there is a folder in the Tomcat conf folder, which also has a web.xml file. This is the file is common to all project files.

Here Insert Picture Description

Here we compare the two documents What is the difference:

1, the front, first code, which is a web-app, which are some of Schema constraints.

Here Insert Picture Description

2, the second segment of code, the servlet is disposed some (but web.xml in which each item is also arranged some servlet). The servlet name is default (default meaning).

Here Insert Picture Description

3, after a third code is skipped. Fourth segment code servlet-mapping, path configuration. Path here url-pattern written inside a slash "/", the "/" is the default meaning.

Here Insert Picture Description

If the virtual path just write "/", meaning that is the default, if we just enter a virtual path in the browser address bar. The virtual path is not, but this time it will have access to (above) the default servlet, the page will be reported abnormal 404 (does not exist). (Default servlet short called "disk access Man")

4, third paragraph of code, there is a jsp, the code can be seen from the servlet-class, it is essentially a servlet. (Tomcat Java-13 specification which contains servlet and jsp.) Remember: jsp essentially servlet.

Here Insert Picture Description

5、第五段代码:这段配置了一个session,里面有个session-timout(值是30)。这个session是指的超时访问时间,即缓存。session是一种缓存技术。有两种缓存技术,一种是session(服务器用于缓存),一种是cookie(客户端浏览器用于缓存)。(session也是一种作用域)

Here Insert Picture Description
这有上面用呢?比如当你登录京东账号之后,倘若你30分钟内不做任何的操作(不动你的鼠标),那么30分钟之后,它就会再次提醒你登录。
默认超时访问是30分钟,这个时间可以更改,但是若是更改之后,以后所有的web项目的访问时间就都变为设置的这个时间了。那么,假如我就想单独的设置某个web项目,怎么办呢?那我们应该在该项目所在的web.xml文件(项目的文件夹web—>WEB-INF下有个web.xml文件)中,配置(增加)一个session-config,里面有个session-timeout,给其赋一个值(如果是10,就是10分钟)。此时,不影响其他的项目。因为当自身的默认访问时间与全局的默认访问时间冲突的时候,先采用自身的。

6、剩下的这些代码一直到倒数第二个,都是<mime-mapping>,这是配置文件的mime-mapping。有什么用呢?

Here Insert Picture Description
比如说,mime-mapping里面有个<extension>avi<extension> , extension翻译过来是文件的扩展的意思,avi是文件的扩展名,这个是给我们看的,当我们看到这个.avi后缀名的时候,我们直到这是视频。但浏览器不认识这个标识。它只认识在后面有一句代码<mime-type>video/x-msvideo</mime-type>,mime-type这个类型,就是给客户端浏览器看的,当浏览器看到video/x-msvideo,它就知道,这是视频,它就会当做视频并播放。

7, the last piece of code: <welcome-file-list>This is the welcome page.

Here Insert Picture Description
When you click the Start Tomcat, it will open a default called "model" of the page. That <welcome-file-list>there are three values, index.html, index.htm, index.jsp, which is the default page three of the opening page. When your web project directory, write a index.html, when the project started, it takes precedence over the index.html page. And when your web page when this project is not index.html. When you open the project, it will default to open systems provided by <welcome-file>index.htm</welcome-file>this page, if here nor <welcome-file>index.htm</welcome-file>this page, then it will open a page for your current project comes at the end of .jsp.

Guess you like

Origin blog.csdn.net/qq_45083975/article/details/92236725