I know that there are several other threads with the same error, but trust me, non of them helped me in solving my issue.
I have a web application built on Java using Struts2 version struts-2.3.16 and Hibernate.
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.
Here is my
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
<?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
<?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>
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
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 the best way to avoid huge struts.xml files is using the Convention plugin.
Consider using it at least for the next projects.