This problem occurs today when using Struts2.1 for annotation operations. It took a half a day to solve, the cause of the mistake is really make people egg ache!
error message:
Project Structure:
Where to use annotations:
Package Com.service;import Java.util.list;import Java.util.map;import javax.servlet.http.httpservletrequest;import Org.apache.struts2.convention.annotation.action;import Org.apache.struts2.convention.annotation.Namespace; Import Org.apache.struts2.convention.annotation.parentpackage;import Org.apache.struts2.convention.annotation.result;import Org.hibernate.event.saveorupdateevent;import Com.biz.goodsbiz;import Com.dao.goodsdao;import Com.domain.goods;import Com.opensymphony.xwork2.ActionContext; Import com.opensymphony.xwork2.actionsupport;/** * Goodsaction.java * * @author Techzero * @Email [email protected] * @Time January 5, 2015 Morning 9:05:11 */@ParentPackage ("Struts-default") @Namespace ("/goods") public class Goodsaction extends Actionsupport {private Goods goods;public Goods getgoods () {return Goods;} public void Setgoods (Goods Goods) {this.goods = Goods;} @Action (value= "FindAll", results={@Result (location= "/admin/goods/show.jsp")}) public String FindAll () throws Exception {goodsbiz GoodsbiZ = new Goodsbiz (); Goodsdao Goodsdao = new Goodsdao (); Goodsbiz.setgoodsdao (Goodsdao); list<goods> goodslist = Goodsbiz.findall (); map<string, object> Requestmap = (map<string, object>) Actioncontext.getcontext (). Get ("request"); Requestmap.put ("Goodslist", goodslist); return actionsupport.success;}}Workaround:
There seems to be no problem, but as soon as the operation of the error! Baidu has not found a half a day, finally found me this package name and other people's not the same, the problem is here! Change service to action, here is the original document for STRUTS2:
First the Convention plugin finds packages named struts, struts2, action or actions. Any packages this match those names is considered the root packages for the Convention plugin. Next, the plugin looks at any of the classes in those packages as well as sub-packages and determines if the classes imple Mentcom.opensymphony.xwork2.Action or if their name ends with Action (i.e. fooaction).
Presumably, if you want to use STRUTS2 annotations, you must place the action class in struts, struts2, action, actions, or its child packages. This rule is really a bit of a pit ...
Struts2 Error: There is no Action mapped for namespace ... Workaround