今天使用struts2 annotation,写了相关jsp文件和继承了ActionSupport的Action类,请求路径都是对的,但总是报错:
There is no Action mapped......
后来网上查了下,原来是Action类除了要继承Action或者名字是XxxAction之外,所在的包也要是struts/struts2/action/actions中的其中一个,不然会扫描不到自己的Action类;
apache给出了说明:http://struts.apache.org/docs/convention-plugin.html#ConventionPlugin-Codebehindhelloworld
These packages are located by the Convention plugin using a search methodology. First the Convention plugin finds packages named struts
, struts2
, action
or actions
. Any packages that match those names are considered the root packages for the Convention plugin. Next, the plugin looks at all of the classes in those packages as well as sub-packages and determines if the classes implement com.opensymphony.xwork2.Action
or if their name ends with Action (i.e. FooAction)。