[转]struts2处理.do后缀的请求

原文地址:http://skyuck.iteye.com/blog/545988

默认情况下,struts2是无法处理以.do为后缀的请求url的(默认情况下是.action或者不填,可以参见org.apache.struts2包下的default.properties文件)。
但是struts2是一个高配置的框架,所以我们可以通过配置来处理以.do为后缀的请求。

struts2提供了一系列的常量来供我们来配置。

如:我们可以在struts.xml文件中配置

Java代码  收藏代码
  1. <constant name="struts.action.extension" value="do"/>  



如果配置多个,可以以逗号分隔开

如:

Java代码  收藏代码
  1. <constant name="struts.action.extension" value="do,action"/>  



使struts2能够处理以.do为后缀的url。

同时我们也可以通过资源文件的方式来配置。

可以在我们项目的类路径下创建一个struts.properties文件。
然后可以在此资源文件中加入

引用

struts.action.extension=do




struts2还提供了其他的方式来加载常量,推荐在struts.xml文件中配置。

struts2加载常量的顺序是:

引用

struts-default.xml
struts-plugin.xml
struts.xml
struts.properties
web.xml



我们可以通过启动tomcat时控制台打印的结果可以看到

引用

信息: Parsing configuration file [struts-default.xml]
2009-12-10 22:47:46 com.opensymphony.xwork2.util.logging.jdk.JdkLogger info
信息: Unable to locate configuration files of the name struts-plugin.xml, skipping
2009-12-10 22:47:46 com.opensymphony.xwork2.util.logging.jdk.JdkLogger info
信息: Parsing configuration file [struts-plugin.xml]
2009-12-10 22:47:46 com.opensymphony.xwork2.util.logging.jdk.JdkLogger info
信息: Parsing configuration file [struts.xml]




在不同的配置文件里存在相同的常量的话,后者将会覆盖前者.

原文地址:https://www.cnblogs.com/dirgo/p/5290846.html