STRUTS2 Error: There is no Action mapped for namespace ... Workaround

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.