解决MyEclipse Struts.xml 中通配符报错“xx cannot be found in the namespace”

来源:互联网 发布:激光设备软件开发 编辑:程序博客网 时间:2024/06/05 03:32

我的思路:

首先确定我的 namespace 没有错,用的缺省 namespace=""。

xx cannot be found in the namespace”,之所以出现类似的错误,

是因为没有一个 actioin 叫做 xxxx 可以是各种东西,

action、通配符 * 、{xxxx},甚至写错了,压根就不存在的东西等。


如果你非常确定你已经写对了,但 MyEclipse 就是报错,可参考下我的解决方案:


<!-- 所有 action 之上写上,表示默认结果:--><default-action-ref name="default" /><!-- 默认的 action,处理不存在的 action --><action name="default"><result type="redirect">NoSuchAction.html</result><result name="error">NoSuchAction.html</result></action><!-- 随便写一个带通配符的 action 做测试 --><action name="*user" method="{1}"><!-- 动态结果 --><result type="redirectAction">${difference}</result><!-- 动态方法 --><result name="1" type="redirectAction">user!reg</result><!-- 瞎写的 --><result name="2">/写什么都不报错了!.aoi.あおい</result><!-- 异常处理 --><result name="input" type="redirect">index.jsp</result></action><!-- 在最后一个 action 之后写上下面的代码(核心)--><!--为了用 * 匹配 MyEclipse 不能匹配的 --><action name="*"><result type="redirectAction">default</result></action>


同时弊端写就出现了:

如果一不小心写错了,

MyEclipse 也不会给予提示了……

所以请大家自行权衡。

建议在杀青的时候,使用本方案。