Search code examples
tomcatservletsapplication-servertomcat7

Servlet mapping to default / in tomcat


I am using an external program that knows to send requests only to localhost:8080/

Is it safe to define the my servlet like this:

<servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

Since also tomcat default servlet is mapped to it. I am using tomcat 7.

What is the priority of the servlets? If I have mapping to /resources/* and *.jsf and the URL is like this localhost:8080/resources/test.jsf - what will be invoked?


Solution

  • If I understood your question correctly, you would want to override the default servlet? You could add a context element within the default <Host> element in tomcat's conf/server.xml

    For example:

    <Context path="" docBase="app" />
    

    where app is a folder in the webapps directory. See the documentation here for more information.

    It is NOT recommended to place elements directly in the server.xml file. This is because it makes modifying the Context configuration more invasive since the main conf/server.xml file cannot be reloaded without restarting Tomcat.

    Hope it helps.