什么是在Tomcat中使用的conf / web.xml与WEB-INF中的那个相反? [英] What is conf/web.xml used for in Tomcat as oppsed to the one in WEB-INF?

查看:792
本文介绍了什么是在Tomcat中使用的conf / web.xml与WEB-INF中的那个相反?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Tomcat部署在conf文件夹下有一个web.xml文件。
Tomcat中使用的conf / web.xml与WEB-INF中的相比是什么?我需要吗?

My Tomcat deployment has a web.xml file under the conf folder. What is conf/web.xml used for in Tomcat as opposed to the one in WEB-INF? Do I need it?

推荐答案

是的,你绝对需要它!它包含默认servlet 的声明和< a href =http://tomcat.apache.org/tomcat-7.0-doc/jasper-howto.html =noreferrer> JSP servlet 。没有它,所有未映射到任何servlet上的请求(例如CSS / JS / images)将停止工作,所有JSP请求将作为普通的未解析源代码返回。

Yes, you definitely need it! It contains among others the declarations of the default servlet and the JSP servlet. Without it, all requests which are not mapped on any of your servlets (e.g. CSS/JS/images) will cease to work and all JSP requests will return as plain unparsed source code.

此外,它还包含一个大的mime类型映射,以便根据文件扩展名设置正确的内容类型。没有它,所有内容将以 application / octet-stream 的形式发送,浏览器可能无法解释内容。

Further it also contains a large mime type mapping so that the right content type will be set based on the file extension. Without it, all content will be delivered as application/octet-stream and the browser may fail to interpret the content.

删除Tomcat自己的 web.xml 。它包含使您的webapp正常工作所需的最少设置。您最多可以更改默认servlet和JSP servlet的初始化参数,例如启用/禁用目录列表以及启用/禁用空白修剪和其他次要性能设置。您还可以在那里添加额外的mime类型映射,但您也可以在webapp自己的 web.xml 上执行此操作。这也在Tomcat的 web.xml 的第一个注释块中明确提到:

Do not remove Tomcat's own web.xml. It contains the minimum set of settings required to get your webapps to work properly. You can at most change the initialization parameters of the default servlet and JSP servlet there, such as enabling/disabling directory listings and enabling/disabling whitespace trimming and other minor performance settings. You can also add extra mime type mappings there, but you could also just do that on your webapp's own web.xml. This is also explicitly mentioned in the first comment block of Tomcat's web.xml:

<!-- ======================== Introduction ============================== -->
<!-- This document defines default values for *all* web applications      -->
<!-- loaded into this instance of Tomcat.  As each application is         -->
<!-- deployed, this file is processed, followed by the                    -->
<!-- "/WEB-INF/web.xml" deployment descriptor from your own               -->
<!-- applications.                                                        -->
<!--                                                                      -->
<!-- WARNING:  Do not configure application-specific resources here!      -->
<!-- They should go in the "/WEB-INF/web.xml" file in your application.   -->

这篇关于什么是在Tomcat中使用的conf / web.xml与WEB-INF中的那个相反?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆