有两个动作,*_*
前面是**
(默认命名空间在特定命名空间之后才起作用(除非特定命名空间扩展它),这无关紧要)
<package name="default" namespace="" extends="struts-default"></package>
<package name="admin" namespace="/admin" extends="default">
<global-results>
<result>/admin/result.jsp</result>
</global-results>
<action name="login" class="org.cc.action.AdminAction">
<result>/admin/admin.jsp</result>
</action>
<action name="*_*" class=org.cc.action.{1}Action" method="{2}">
</action>
</package>
<package name="error" namespace="" extends="default">
<action name="**" >
<result>/error.jsp</result>
</action>
</package>
我为捕获不存在的操作定义了一个错误页面
然后我测试了这个动作
localhost:8080/myProjectName/admin/AdminAction.action
(它不存在)
但它被命名的操作捕获,"*_*"
因为显示AdminActionAction.class
未找到异常。
然后我用了*__*
(有两个'_'
)。它运行良好并显示了error.jsp
.
格式喜欢"*a*"
或"*#*"
不起作用,即使#
在动作的名称中没有 a 和,他们也会捕捉到任何动作。
我使用 Struts 2.3.4。
之间是否有任何文件,*
并且*
必须至少有两个字符,否则就像 一样*
?
这是异常的详细信息
Unable to instantiate Action, org.cc.action.AdminActionAction, defined for 'AdminAction' in namespace '/admin'org.cc.action.AdminActionAction
com.opensymphony.xwork2.DefaultActionInvocation.createAction(DefaultActionInvocation.java:319)
com.opensymphony.xwork2.DefaultActionInvocation.init(DefaultActionInvocation.java:400)
com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:194)
org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63)
org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:501)
org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
java.lang.ClassNotFoundException: org.cc.action.AdminActionAction
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1711)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1556)
com.opensymphony.xwork2.util.ClassLoaderUtil.loadClass(ClassLoaderUtil.java:152)
com.opensymphony.xwork2.ObjectFactory.getClassInstance(ObjectFactory.java:108)
com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:161)
com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:151)
com.opensymphony.xwork2.ObjectFactory.buildAction(ObjectFactory.java:121)
com.opensymphony.xwork2.DefaultActionInvocation.createAction(DefaultActionInvocation.java:300)
com.opensymphony.xwork2.DefaultActionInvocation.init(DefaultActionInvocation.java:400)
com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:194)
org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63)
org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:501)
org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
很容易看出
localhost:8080/myProjectName/admin/AdminAction.action
(它不存在)被抓住了
<action name="*_*" class="net.org.cc.{1}Action" method="{2}">