由于Struts2的版本在不断的更新,对文件的配置要求也有了一些改变。
对于Struts2.5以上的版本如果需要url+!+方法访问Action某个方法的话需要在struts.xml加入如下语句
以上两句是DIM(动态访问犯法的配置)
有时候可以还会出现 Method 方法 for action Action is not allowed
这时候可能需要在struts.xml中package中加入继续加入如下语句
还有别忘了把项目的输出设置到WEB-INF下的classes文件里,如图
最后我附上一个配置的例子
在这之前你需要下载如下一下struts包并加载到libraries里,这些类可以去Apache官网下载
有有时候有些包需要放到tomcat的lib里面才可以,不敢上述的包不需要
1、首先我们配置一下web.xml
其中org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter过滤器是struts2.5后由org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter改过而来的
2、配置struts.xml
这个如果嫌难打的话可以去源码包拷贝,class指定是action的类名
3、UserAction类
4、index.jsp
5、delete.jsp
6、add.jsp