Reputation: 280
To have a home-page servlet which will generate home page's content, I kept url-pattern empty in the servlet-mapping, which AFAIK maps to the context root, say like mysite.com/ or http://{host}:{port}/mysite/
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>My site</display-name>
<servlet>
<servlet-name>controller</servlet-name>
<servlet-class>com.mysite.control.MainController</servlet-class>
<!-- Load this servlet at server startup time -->
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>controller</servlet-name>
<url-pattern></url-pattern>
</servlet-mapping>
The above is the complete web.xml (except root element web-app). But Tomcat 7.0.26 gives following error during startup due to which the war is not getting deployed.
SEVERE: ContainerBase.addChild: start:
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/mysite]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:895)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:871)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:615)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:958)
...
Caused by: java.lang.IllegalArgumentException: Invalid <url-pattern> in servlet mapping
at org.apache.catalina.core.StandardContext.addServletMapping(StandardContext.java:3208)
...
Note 1: This is not a spring project, it is pure servlet 3.0 project and just has web.xml configuration at the moment.
Note 2: The class com.mysite.control.MainController does exist.
How can I fix this? I know welcome-file is an option to mimic home page but that is not optimal and I would prefer to fix this instead. Is this tomcat 7.0.26 bug or some other issue?
Upvotes: 0
Views: 1419
Reputation: 5122
This is a bug of Tomcat and have been fixed since 7.0.28. Please refer to this page. So you should update Tomcat.
Upvotes: 1