on 2015 Aug 09 5:08 PM
Hi community,
I'm currently playing around with Java servlets on HCP and I'm not overly familiar with that.
Currently, I have this piece of config in my web.xml:
<servlet-mapping>
<servlet-name>HelloWorldServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
This works perfectly fine and my app is properly deployed. However, when I change the url pattern to something else (e.g. to / or /hello-world/*), the service remains in Starting state.
There's the following log entry:
Failed to start web application at context path '/HelloWorld'
org.eclipse.gemini.web.core.spi.ServletContainerException: Web application at '/HelloWorld' cannot be added to the host.
at org.eclipse.gemini.web.tomcat.internal.TomcatServletContainer.startWebApplication(TomcatServletContainer.java:128)
[...]
I can't really make sense of it. Does anyone have an idea about what might cause this?
Thanks,
Max
Request clarification before answering.
Hello,
There should be more information in the logs. Can you please share the whole exception not only part of it.
Regards,
Violeta
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Indeed, there's something interesting hidden deep in the logs: (full log attached)
Caused by: java.lang.IllegalArgumentException: The servlets named [HelloWorldServlet] and [helloworld.HelloWorldServlet] are both mapped to the url-pattern [/] which is not permitted
But I still cannot make sense of it.
Here's the web.xml (omitted some resource-ref's and init-param's but that shouldn't make a difference)
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>helloworld</display-name>
<servlet>
<servlet-name>MyODataSampleServlet</servlet-name>
<servlet-class>org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet</servlet-class>
<!-- more config -->
</servlet>
<servlet>
<servlet-name>HelloWorldServlet</servlet-name>
<servlet-class>helloworld.HelloWorldServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MyODataSampleServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
Again, when I change the url-pattern from /* to /, I get the above error.
Thanks in advance!
- Max
Hi,
The exception says the following:
you have servlet with name X in the web.xml which is mapped to a concrete url pattern.
and you have again servlet with name Y annotated with @WebServlet which is mapped to the same url pattern.
Please note that when you do not specify a name in @WebServlet then the Web Container will use as servlet name the fully qualified class name i.e. package + classname
For Web Container servlet name matters so you may end up with one and the same servlet class with different names (the first specified in the web.xml and the second - default from annotation - fully qualified class name) - from Web Container point of view these are different servlets.
So please ensure that you are using either web.xml or annotations.
Regards,
Violeta
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 17 | |
| 8 | |
| 7 | |
| 6 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.