Reputation: 980
I am going to submit a form via jQuery AJAX in Struts 2.
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>
<constant name="struts.devMode" value="true" />
<constant name="struts.ui.theme" value="simple" />
<package name="default" extends="struts-default">
<action name="loginSubmit"
class="com.myproj.portal.controllers.PhysicianLoginController"
method="execute">
<result name="success">/landing.jsp</result>
<result name="failure">/staff-login.jsp</result>
</action>
<action name="logout"
class="com.myproj.portal.controllers.PhysicianLoginController"
method="logout">
<result name="success">/Welcome.htm</result>
</action>
<action name="demographics"
class="com.myproj.portal.controllers.DemographicsController"
method="execute">
<interceptor-ref name="token" />
<interceptor-ref name="basicStack" />
<result name="success">/demographics.jsp</result>
<result name="failure">/demographics.jsp</result>
<result name="invalid.token">/demographics.jsp</result>
</action>
</package>
<package name="example" extends="struts-default,json-default">
<action name="chngpass" class="com.myproj.portal.controllers.ChangePasswordController"
method="execute" >
<result name="success" type="json" />
</action>
</package>
</struts>
I have added the JSON plugin jar in my lib folder. But this raises the following error
12:40:41,236 ERROR [DomHelper] The content of element type "package" must match "(result-types?,interceptors?,default-intercept
org.xml.sax.SAXParseException: The content of element type "package" must match "(result-types?,interceptors?,default-interceptor-ref?,default-action-ref?,
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
Whats wrong with it ?
Upvotes: 0
Views: 1931
Reputation: 3204
To get a result type of json
, you don't need to define the following
<result-types>
<result-type name="json" class="org.apache.struts2.json.JSONResult"/>
</result-types>
<interceptors>
<interceptor name="json" class="org.apache.struts2.json.JSONInterceptor"/>
</interceptors>
Remove the above declarations.
Secondly, your package declaration should be in struts
element. So in the end, you should have something like this
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="example" namespace="/your_name_space" extends="struts-default,json-default">
<action name="chngpass" class="com.myproj.portal.controllers.ChangePasswordController"
method="execute" >
<result name="success" type="json" />
</action>
</package>
</struts>
Upvotes: 0