问题描述
我同时配置了 Struts 2 和 Spring MVC.我的 web.xml
如下所示.当我点击 REST URL 上传文件时,它会调用 struts 调度程序而不是 Spring.
I have both Struts 2 and Spring MVC configured. My web.xml
looks like below. When I hit a REST URL to upload file, it invokes struts dispatcher instead of Spring.
为什么 URL /rest/uploadfile/iec9.pdf
要去 Struts Dispatcher?
Why URL /rest/uploadfile/iec9.pdf
is going to Struts Dispatcher?
web.xml
:
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>springmvc-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc-dispatcher</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/springmvc-dispatcher-servlet.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<filter>
<filter-name>jsonpCallbackFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>jsonpCallbackFilter</filter-name>
<url-pattern>*.json</url-pattern>
</filter-mapping>
推荐答案
您的 spring MVC 调度程序 servlet 被映射到 Struts 过滤器处理的 URL 子集.至于过滤器在任何其他 servlet 之前调用,那么它将具有优先权.要解决此问题,您需要配置 Struts 以从映射中排除某些 URL.
Your spring MVC dispatcher servlet is mapped to the subset of URLs handled by the Struts filter. As far as filter invoked before any other servlets then it will have precedence. To workaround you need to configure Struts to exclude some URLs from mapping.
<struts>
<constant name="struts.action.excludePattern" value="/rest/?.*"/>
...
</struts>
这篇关于为什么请求要去Struts Dispatcher?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!