Struts2错误:There is no Action mapped for namespace... 解决方法
来源:互联网 发布:光大金阳光软件 编辑:程序博客网 时间:2024/05/16 10:40
今天在使用 Struts2.1 做注解操作的时候,一直出现这个问题。花了半天时间才解决,错误原因真是让人蛋疼!
错误提示:
项目结构:
使用注解的位置:
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 techzero@163.com * @Time 2015年1月5日 上午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;}}
解决方法:
看上去没有任何问题,可是只要一运行就报错!百度了半天没找到,最后发现我这个包名跟别人的不一样,问题就出在这里!将service换成action就可以了,以下是Struts2的原文文档:
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 implementcom.opensymphony.xwork2.Action or if their name ends with Action (i.e. FooAction).
大概意思是,如果要用Struts2的注解,必须要将action处理类放在struts, struts2, action, actions包或者其子包中。这个规定真心有点坑。。。
0 0
- Struts2错误:There is no Action mapped for namespace... 解决方法
- Struts2注解错误There is no Action mapped for namespace [/].....
- struts2中的There is no Action mapped for namespace [/] 错误
- struts2关于"There is no Action mapped for namespace / and action name"的解决方法
- struts2.5.5 bug There is no Action mapped for namespace
- 彻底解决STRUTS2 错误There is no Action mapped for namespace / and action name login
- 解决STRUTS2 错误 There is no Action mapped for namespace / and action name
- struts2种出现的There is no Action mapped for namespace [/] and action name 错误
- struts2配置错误 There is no Action mapped for namespace [/] and action name [] associated with context
- struts2提示“There is no Action mapped for namespace [/] and action name [XXX]... ”错误的解决办法
- Struts2中关于"There is no Action mapped for namespace / and action name"错误
- struts2.5错误-There is no Action mapped for namespace [/] and action
- Struts2中关于"There is no Action mapped for namespace / and action name"的错误解决
- Struts2的There is not Action mapped for namespace [/] 错误
- There is no Action mapped for namespace
- There is no Action mapped for namespace
- There is no Action mapped for namespace
- Struts2注解错误之There is no Action mapped for namespace [/]……
- Groovy&Grails
- Nginx 反向代理 websocket
- Nginx反向代理、防盗图
- 指针相关问题
- Node.js 体验报告——有关 Node.js 的集中吐槽
- Struts2错误:There is no Action mapped for namespace... 解决方法
- Groovy入门教程
- 旋屏操作
- 不要在MCU函数里面定义超过几十个字节的数组
- ios编译RegexKitLite的时候报错解决方法
- NSObject 的 load 方法
- log4j 详解(二)
- Groovy常用语法总结
- 悼念512汶川大地震遇难同胞——来生一起走