Struts2中关于"There is no Action mapped for namespace / and action name"的错误解决

来源:互联网 发布:淘宝c店铺运营计划表 编辑:程序博客网 时间:2024/06/04 18:19

今天在调试一个十分基础的Struts2框架小程序时。总是提示”There is no Action mapped for namespace / and action name”的错误。找了好长时间也没解决,灰常苦恼。最终,竟然是一个小小的拼写错误,蓝瘦香菇。这是一个初学者经常碰到的问题,导致错误的原因主要有两种。总结如下:
1.—–首先查看你的struts.xml 文件是否在src目录下;

最重要的是还要检查struts是否拼写错误。(我就是因为这个的拼写错误才出现这样的问题的)

2.—–检查struts.xml文件的语法是否正确:

如果1检查之后没有错误,那基本就是语法的问题了。

<?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="save" class="org.action.SaveAction">        <result name="success">/success.jsp</result>        <result name="error">/index.jsp</result>       </action>    </package></struts>

其中,
namespace 属性是可选的, 如果它没有给出, 则以 “/” 为默认值. 若 namespace 有一个非默认值, 则要想调用这个包里的Action, 就必须把这个属性所定义的命名空间添加到有关的 URI 字符串里

action 元素的 class 属性是可选的. 如果没有配置 class 属性, Struts 将把 com.opensymphony.xwork2.ActionSupport 作为其默认值. 如果配置了 class 属性, 还可以使用 method 属性配置该类的一个动作方法. method 属性的默认值为 execute

1 0