tags:

views:

3703

answers:

1

I want to use json with Struts2. However, when I set the action return type to "json", I got "there is no result type defined for type 'json' mapped with name 'success'." Bellow is struts.xml file.

<?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"&gt;
<struts>
    <constant name="struts.custom.i18n.resources" value="resource"/>

    <package extends="struts-default" name="test">
     <action name="inputHandler" class="inputHandlerAction">
      <result name="input">/index.jsp</result>
      <result>/result.jsp</result>
     </action>
     <action name="setLangHandler" class="com.sesoft.test.setLanguageHandler">
      <result>/index.jsp</result>
     </action>

     <action name="Handler" class="com.sesoft.test.Handler">
      <result>/test2.jsp</result>
     </action> 
    </package>

    <package name="example" extends="json-default">

     <action name="ajaxHandler" class="com.sesoft.test.AjaxHandler">
      <result name="success" type="json" />
     </action>

    </package>
</struts>

Before I added the json Action, all other action performs fine. But after I added the json Action, the server failed to action with error code 503.

libs I've added "jsonplugin-0.33.jar" to the lib directory.

+2  A: 

You don't have the JSON result defined in your struts.xml package. If you only need default things then you can just extend json-default instead of struts-default. If you need to customise the package then include the following and that should do the trick:

    <result-types>
        <result-type name="json" class="com.googlecode.jsonplugin.JSONResult"/>
    </result-types>
Peter Kelley