Zac*_*ter 2 java struts2 web-applications spring-mvc
我正在尝试将Struts2应用程序(版本2.2.1.1)迁移到Spring MVC,并且我很难将struts.xml映射转换为SpringMVC servlet映射.
我的第一个问题是Struts2究竟是如何排除模式的.让我们说在我的web.xml中我有一个struts2的过滤器/映射设置如下:
<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>
在我的struts.xml中,我定义了一系列已经正常工作的动作.现在从我的理解,基于struts2文档 -
(从Struts 2.1.7开始,你可以提供一个逗号分隔的模式列表,当匹配请求URL时,Filter将只传递.这是通过配置选项struts.action.excludePattern完成的,例如在你的struts.xml) -
如果我添加排除模式,例如:
<constant name="struts.action.excludePattern" value="/*"/>
然后应该绕过过滤器并且上面提到的操作不应该解决,对吗?
出于某种原因,这种情况并没有发生,我的所有行动仍在适当地进行.
是什么赋予了?
排除模式是一个正则表达式。
如果你想排除一切,你会想要.*.
http://struts.apache.org/2.x/docs/webxml.html#web.xml-SimpleExample
我不知道你为什么想要那个,因为你可以删除 S2 过滤器。
小智 5
struts值必须遵守java.util.regex.Pattern类标准. http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html
所以,如果你想避免所有/ rest/*url例如:
/rest/[a-zA-Z_0-9]*
如果,您需要处理具有多个参数的休息Web服务:
/rest/[a-zA-Z_0-9]*/?[a-zA-Z_0-9]*/?[a-zA-Z_0-9]*/?[a-zA-Z_0-9]*/?[a-zA-Z_0-9]*
为了测试您的模式,您可以使用以下代码:
Pattern pattern = Pattern.compile("/rest/[a-zA-Z_0-9]*/?[a-zA-Z_0-9]*/?[a-zA-Z_0-9]*/?[a-zA-Z_0-9]*/?[a-zA-Z_0-9]*");
String uri = "/rest/users/1/1";
System.out.println(pattern.matcher(uri).matches());
| 归档时间: | 
 | 
| 查看次数: | 13663 次 | 
| 最近记录: |