Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the meaning of <enabled>false</enabled> for a servlet definition in web.xml?

Seems that web.xml for a servlet has an element called

<enabled>false</enabled>

that can be put in the servelt definition like so

<servlet>
    <servlet-name>example</servlet-name>
    <servlet-class>com.example.TestServlet</servlet-class>
    <load-on-startup>100</load-on-startup>
    <enabled>false</enabled>
</servlet>

Does enabled refer to the ability of the servlet to process requests? I noticed that even if I set enabled to false the init method of the the servelt gets called. Searching through the servlet spec pdf did not provide an explanation of the meaning of <enabled> in fact I could not even find the string <enabled> in the servlet 3.0 spec.

like image 549
ams Avatar asked Jan 30 '26 13:01

ams


2 Answers

From the Java Servlet 3.0 specification, 8.2.3 section 3 (see the pdf):

If a servlet is disabled using the enabled element introduced in the web.xml then the servlet will not be available at the url-pattern specified for the servlet.

Edit: Here's another post on this exact topic: How to make sure that servlet is not loaded?

Edit 2: (putting summary from comments below in here) In Tomcat 7 (as of 7.0.25) it appears that the Servlet will initialize but requests to its url-pattern will respond with a status code 503 (SC_SERVICE_UNAVAILABLE)

like image 109
Adam Rofer Avatar answered Feb 01 '26 02:02

Adam Rofer


I can't find it anywhere indeed, apart from the XSD. If it still handles requests (check that), then I guess it is added there for future use, or to let containers decide what to do with it.

like image 40
Bozho Avatar answered Feb 01 '26 03:02

Bozho