2.5.5版本套路一
出现异常
There is no Action mapped for namespace [/] and action name [roleAction_addUI] associated with context path [/OA]. - [unknown location]
com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:192) org.apache.struts2.factory.StrutsActionProxy.prepare(StrutsActionProxy.java:63) org.apache.struts2.factory.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:37) com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58) org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:554) org.apache.struts2.dispatcher.ExecuteOperations.executeAction(ExecuteOperations.java:81) org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:113) org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220) org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505) org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956) org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423) org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079) org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625) org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316) java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) java.lang.Thread.run(Unknown Source)
解决办法,在包节点中加入如下开通禁用的通配符即可
<package name="cai" namespace="/" extends="struts-default"
strict-method-invocation="false">
注意版本:
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration
2.5
//EN"
"http://struts.apache.org/dtds/struts-
2.5
.dtd">
套路2:
filterDispatcher不再使用
2.3.24.1如下:
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
2.5 版本中如下
org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter
其他常亮的配置:
<constant name="struts.ui.theme" value="simple"></constant>
<!-- 配置为开发模式,更改文件配置之后不用重新启动,可以看到更多的错误信息 -->
<constant name="struts.devMode" value="true"></constant>
<constant name="struts.configuration.xml.reload" value="true"></constant>
<!-- 禁止缓存 -->
<constant name="struts.serve.static.browserCache" value="false" />
<!-- 配置扩展名 -->
<constant name="struts.action.extension" value="action" />
<!-- 启用DMI 设置是否支持动态方法调用,true为支持,false不支持. -->
<constant name="struts.enable.DynamicMethodInvocation" value="true" />
<!-- 设置编码 -->
<constant name="struts.il8n.encoding" value="UTF-8" />
<!-- 由spring 管理action的创建 -->
<constant name="struts.objectFactory" value="spring" />
<!--当使用约定时,指定扫描Controller 结尾的类为Action -->
<constant name="struts.convention.action.suffix" value="Controller"/>
<!--当使用约定时,获取Action 所指定的扫描的包-->
<constant name="struts.convention.package.locators" value="example"/>