我试图在一个web.xml中运行两个Servlet类,但它不起作用,每个servlet类独立工作正常.
web.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>
如果你能解决我正在做的事情,请告诉我.
我尝试了以下链接,但它对我不起作用
Can I use Spring MVC and Spring WS in one single application?
解决方法
这不会起作用.映射在/ *上的那个超过了所有请求.您需要在/上映射它,以便它只拦截与所有其他现有servlet不匹配的请求(包括隐式映射到* .jsp的JSP servlet和所有“普通”静态资源,如CSS / JS /图像文件!).另见
Difference between / and /* in servlet mapping url pattern.
如果还需要能够提供静态资源,那么最好将其映射到更具体的URL模式,如/ ws / *,并创建一个Filter来检查请求URI,然后相应地转发.该过滤器可以安全地映射到/ *.有关更具体的代码示例,请参阅此答案:How to access static resources when mapping a global front controller servlet on /*.