最近在捯饬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实例。
如果想解决,其实很简单,直接调整通配符的规范,不能以*号直接开头和结尾。