Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 737
sproketboy Avatar asked May 09 '11 13:05

sproketboy


People also ask

What is the use of web xml in Tomcat?

XML. The web. xml file is derived from the Servlet specification, and contains information used to deploy and configure the components of your web applications. When configuring Tomcat for the first time, this is where you can define servlet mappings for central components such as JSP.

What is Conf web XML file?

web. xml defines mappings between URL paths and the servlets that handle requests with those paths. The web server uses this configuration to identify the servlet to handle a given request and call the class method that corresponds to the request method (e.g. the doGet() method for HTTP GET requests).

Where is the Web XML file in Tomcat?

It is located in the TOMCAT_ROOT_DIR\conf folder. This configuration file is used for basic web application's configuration shared by all web applications that will be deployed on the Tomcat server instance. Each of the web application may optionally override shared configurations by defining their own web.

What is web INF web xml?

/WEB-INF/web. xml - The Web Application Deployment Descriptor for your application. This is an XML file describing the servlets and other components that make up your application, along with any initialization parameters and container-managed security constraints that you want the server to enforce for you.


2 Answers

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.   --> 
like image 113
BalusC Avatar answered Oct 09 '22 04:10

BalusC


The web.xml under WEB-INF is a deployment descriptor which is applied to the current web application only and as such controls the running of just that web app. It allows you define your servlets, servlet mapping to URLs, context (startup) parameters etc. The web.xml under Tomcat's conf directory defines the default parameters for ALL applications on a Tomcat instance. In theory, this could be missing but then all of the web application deployed will have to define all of the settings in it -- such that .jsp pages are processed by the JspServlet (which will compile them and load the generated servlet etc), all the mime mappings and default file lists (for those apps that don't specifiy it). Think of it as a set of defaults which you can always override, however, they are there for your convenience so you don't have to define them for each app.

like image 21
Liv Avatar answered Oct 09 '22 03:10

Liv