您的位置:首页 > 移动开发

Struts2中"There is no Action mapped for namespace / and action name"

2014-07-18 08:25 351 查看
昨天遇到的小问题,我也不是初学了,检查了下配置文件都没问题啊,后来发现了问题所在:

struts.xml中的配置是这样写的:

<action name="usercenter" class="com.action.MainAction" method="usercenter">
	<result>/usercenter/UserCenter.jsp</result>
	<result name="error">test.jsp</result>
</action>


本意是通过action:usercenter去找usercenter文件夹下的UserCenter.jsp。但是url为usercenter时就老报 no Action mapped的错误,只能通过usercenter.action去访问,后来发现action的name不能和文件夹的名字相同,改成:

<result>/theusercenter/UserCenter.jsp</result>
就好了。

另外还搜到了一篇对初学者很好的文章:

今天在调试一个基础的Struts2框架小程序。总是提示"There is no Action mapped for namespace / and action name"的错误。上网查询后发现这是一个初学者经常碰到的问题,导致错误的原因主要有两种。总结如下:

一、struts.xml文件错误。这种错误又分为以下几种:1,struts.xml文件名错误。一定要注意拼写问题;2,struts.xml文件放置路径错误。一定要将此文件放置在src目录下。编译成功后,要确认是否编译到classes目录中;3,struts.xml文件内容错误。下面给出一个正确的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="default" namespace="/" extends="struts-default">
        <action name="login" class="com.wanggc.struts2.sample.Struts2Action">
        <result name="success">/jsp/result.jsp</result>
        </action>
    </package>
</struts>






二、如果排除了struts.xml文件的问题,还有一种可能就是,在web.xml文件中的<welcome-file>信息中是否配置了自己工程的启动页面。如果没有配置,地址栏中要输入完成的url,如:http://localhost:8080/Struts2Sample/jsp/login.jsp,后面的资源详细信息不输入的时候也会报这个错误,我就是栽在这个问题上的(^_^)。
转自:http://www.cnblogs.com/gulvzhe/archive/2011/11/21/2256632.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐