Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
161 views
in Technique[技术] by (71.8m points)

java - What is conf/web.xml used for in Tomcat as oppsed to the one in 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

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.

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.   -->

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...