There is no Action mapped for namespace / and action name getEmployee

在对Spring3和对Struts2进行集成时,写了一个简单的action进行测试。结果服务器老报“There is no Action mapped for namespace / and action name getEmployee”异常,页面出现404错误。

 

action的代码清单如下:

package com.ssh.action;

 

public class EmployeeAction extends BaseAction{

    public String getEmployee(){
        System.out.println("--aaaaaaaaaaaaaaaaaaaaaa----");
        return "success";
    }
}

 

struts.xml的配置如下:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
 <package name="employee" namespace="/" extends="struts-default">
   
  <action name="getEmployee" class="com.ssh.action.EmployeeAction" method="getEmployee">
   <result>/index.html</result>
  </action>

 </package>

</struts>

 

刚开始还以为是action的配置错误。而且就这么简单的配置,也不可能会配置错啊,找了好久,也没有发现那里不对。而且也看了web.xml的配置,也没有错。整郁闷之时,在网上搜了下,有人说是struts.xml文件的位置放错了,说是要直接放在src下面。然后我看了下我工程中struts.xml文件的位置,发现它是在src下面,只不过处于src目录的config子目录(本意是专门用来放所有配置文件的)中。莫非是因为这个引起来的?然后我直接把struts.xml文件移到src目录下面,重启服务器。然后输入地址,访问成功,控制台输出了字符串--aaaaaaaaaaaaaaaaaaaaaa----,而且也调到了index.html页面。问题找到了!

 

通过此次测试和网友的经验,如果出现类似“There is no Action mapped for namespace / and action name getEmployee”的异常时,应该通过以下几种方式进行排除:

1:首先还是检查struts.xml文件的配置,看看对应的action配置是否正确;

2:如果action的配置没有问题,则看看struts.xml的位置是否正确(struts2中此文件默认只能直接放在src目录中,也就是编译后的classes目录中;而不能将struts.xml放在他们的子目录中,否则struts会加载不到)

3:确定名称是 struts.xml。

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值