没有与命名空间[/]映射的动作和与上下文路径[/ SampleTC_test]关联的操作名称[viewBooks]。 - [未知位置] [英] There is no Action mapped for namespace [/] and action name [viewBooks] associated with context path [/SampleTC_test]. - [unknown location]
问题描述
我知道有几个其他线程有相同的错误,但相信我,非他们帮助我解决我的问题。
I know that there are several other threads with the same error, but trust me, non of them helped me in solving my issue.
我有一个Web应用程序基于Java使用Struts2版本struts-2.3.16和Hibernate。
I have a web application built on Java using Struts2 version struts-2.3.16 and Hibernate.
我的问题是,在我的应用程序中我有struts.xml,因为它的巨大的大小,分成三个xml文件。一个是主要的struts.xml,其中包含两个include标签,它们指向同一应用程序的两个不同的strtus-XXX.xml文件。我的问题是,只有一个struts-XXX.xml是工作,我在第二个XML文件中写的操作不工作。如果我的应用程序试图指出在第二个xml文件中提到的任何动作,它不会被识别。
My issue is, in my application I have struts.xml, because of it's huge size i split it into three xml files. One is main struts.xml which contains two include tag which points out to two different strtus-XXX.xml file's of the same application. My problem is that only one struts-XXX.xml is working and what ever the actions I write in the 2nd xml file are not working. If my application is trying to point out any "action" which was mentioned in the 2nd xml file it is not getting recognized.
这里是我的
struts.xml代码
struts.xml code
<?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>
<constant name="struts.enable.DynamicMethodInvocation"
value="false" />
<constant name="struts.devMode" value="true" />
<constant name="struts.custom.i18n.resources"
value="ApplicationResources" />
<include file="struts/struts-codeGroup.xml"/>
<include file="struts/struts-book.xml"/>
</struts>
struts-codeGroup.xml
struts-codeGroup.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>
<constant name="struts.convention.result.path" value="/WEB-INF/"/>
<constant name="struts.enable.DynamicMethodInvocation"
value="false" />
<constant name="struts.devMode" value="true" />
<constant name="struts.custom.i18n.resources"
value="ApplicationResources" />
<package name="default" namespace="/" extends="struts-default">
<action name="viewCodeValues" class="com.hibernate.action.CodeValuesAction">
<result name="success">/ViewCodeValues.jsp</result>
</action>
</package>
</struts>
struts-book.xml
struts-book.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>
<constant name="struts.convention.result.path" value="/WEB-INF/"/>
<constant name="struts.enable.DynamicMethodInvocation"
value="false" />
<constant name="struts.devMode" value="true" />
<constant name="struts.custom.i18n.resources"
value="ApplicationResources" />
<package name="default" namespace="/" extends="struts-default">
<action name="viewBooks" class="com.hibernate.action.BookAction" method="viewBooks">
<result name="success">/viewBooks.jsp</result>
</action>
</package>
</struts>
包含标签with struts-codeGroup.xml工作正常,但struts-book.xml中的操作正在给我错误
Include tag with struts-codeGroup.xml is working fine but actions in struts-book.xml are not working at all and are giving me the error
没有为名称空间映射操作[
/ $ c与上下文路径[
/ SampleTC_test
]相关联的动作名称[$ c>]和动作名称[viewBooks
]。 - [未知位置]
There is no Action mapped for namespace [
/
] and action name [viewBooks
] associated with context path [/SampleTC_test
]. - [unknown location]
推荐答案
不能有两个包名称相同。使用类似
You can't have two packages with the same name. Use something like
<package name="default1" namespace="/" extends="struts-default">
<!-- ... -->
</package>
<package name="default2" namespace="/" extends="struts-default">
<!-- ... -->
</package>
BTW避免巨大的struts.xml文件的最好方法是使用常规插件。
请考虑至少使用 下一个项目。
BTW the best way to avoid huge struts.xml files is using the Convention plugin.
Consider using it at least for the next projects.
这篇关于没有与命名空间[/]映射的动作和与上下文路径[/ SampleTC_test]关联的操作名称[viewBooks]。 - [未知位置]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!