Java – in a single web Adding multiple servlets to XML
I tried on a web Two servlet classes run in XML, but it doesn't work. Each servlet class works independently
web. In XML:
<servlet>
<servlet-name>spring-ws</servlet-name>
<servlet-class>org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-class>
<init-param>
<param-name>transformWsdlLocations</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring-ws</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>240</session-timeout>
</session-config>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-ws-servlet.xml
/WEB-INF/health-page-servlet.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>health-page</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>health-page</servlet-name>
<url-pattern>/health.htm</url-pattern>
</servlet-mapping>
If you can solve what I'm doing, please let me know
Can I use spring MVC and spring WS in one single application?
Solution
It won't work The one mapped on / * exceeds all requests You need to project it in / so that it only intercepts requests that do not match all other existing servlets (including JSP servlets implicitly mapped to *. JSP and all "normal" static resources, such as CSS / JS / image files!) See also difference between / and / * in servlet mapping URL pattern
If you also need to be able to provide static resources, it is best to map them to a more specific URL pattern, such as / WS / *, and create a filter to check the request URI, and then forward it accordingly The filter can be safely mapped to / * For more specific code examples, see this answer: how to access static resources when mapping a global front controller servlet on / *
