我把struts.xml没有放到src下,而是根据自己的习惯放到新目录:WEB-INF/conf/下了。这时候需要在web.xml中进行必要的配置,配置情况如下:
- <filter>
- <filter-name>struts2</filter-name>
- <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
- <init-param>
- <param-name>config</param-name>
- <param-value>struts-default.xml,struts-plugin.xml,/WEB-INF/conf/struts.xml</param-value>
- </init-param>
- </filter>
<这时候在IE地址栏中访问:http://localhost:8080/test/ddd
时会报错,错误信息如下:
警告: Could not find action or result
There is no Action mapped for namespace / and action name ddd. - [unknown location]
at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:178)
at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61)
at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:47)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:478)
解决办法如下:
只要对web.xml稍做一点改动就行,改成如下:
- <filter>
- <filter-name>struts2</filter-name>
- <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
- <init-param>
- <param-name>config</param-name>
- <param-value>struts-default.xml,struts-plugin.xml,../conf/struts.xml</param-value>
- </init-param>
- </filter>