struts2处理.do后缀的请求

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

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

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

<constant name="struts.action.extension" value="do"/>


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

如:

<constant name="struts.action.extension" value="do,action"/>


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

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

可以在我们项目的类路径下创建一个struts.properties文件。
然后可以在此资源文件中加入
[quote]
struts.action.extension=do
[/quote]


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

struts2加载常量的顺序是:
[quote]
struts-default.xml
struts-plugin.xml
struts.xml
struts.properties
web.xml
[/quote]

我们可以通过启动tomcat时控制台打印的结果可以看到
[quote]
信息: 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]
[/quote]


在不同的配置文件里存在相同的常量的话,后者将会覆盖前者.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值