Struts2的默认action配置真的是bug?

最近在捯饬struts2,其中在学习一个namespace中的默认action的时候,遇到了一个问题,先提供下struts的配置文件如下:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
	"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
	"http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>
   
    <package name="test" namespace="/test" extends="struts-default">
    <default-action-ref name="index"/>
        <action name="index" class="com.yp.action.UITestAction">
            <result >/test/test.jsp</result>
        </action>
    </package>
</struts>

当我进行访问的时候,当录入的action为配置的或者为随意录入的,以上的配置是没有问题的。

But,当我在test包中配置了通配符的action的时候(如*_*),在随意录入action的名称,会提示我,找不到指定的实例Action,刚开始觉得是个bug,后来到官网上查到了东西,如下:

--

, if an action is requested, and the framework can't map the request to an action name, the result will be the usual "404 - Page not found" error. But, if you would prefer that an omnibus action handle any unmatched requests, you can specify a default action. If no other action matches, the default action is used instead.大体的意思是,当请求一个action时候,struts2框架会去寻找指定的action的name。

如果配置了通配符,并且还是以例子中的这种*_*配置模式,那么通配符模式,会将你的随意的请求的action配置成第一个星,并且还去找这个action实例,因此这个时候,往往提示找不懂指定的action实例。

如果想解决,其实很简单,直接调整通配符的规范,不能以*号直接开头和结尾。

 

 

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值