No result defined for action <class> and result input

雨燕双飞 提交于 2021-01-28 01:39:02

问题


Here is my struts.xml

<package name="ajax" extends="json-default" >
    <action name="loadcity"  method="loadcity" class="roseindia.action.user.RegisterUser" >
        <result  type="json" />
    </action>
</package>

When I am calling loadcity.action I am getting following error

No result defined for action roseindia.action.user.RegisterUser and result input

Here is my action method:

public String loadcity()
{ 
    country=request.getParameter("country");

    cityList=  dao.loadcity(country);
    return ActionSupport.SUCCESS;
}

回答1:


First of all your srtuts.xml file is not completely defining the result type which should be render on the response of you action execution .result tag plays the role of a view in the Struts2 MVC framework. The action is responsible for executing the business logic. The next step after executing the business logic is to display the view using the tag. Here you can do one thing

<package name="ajax" extends="json-default" >
    <action name="loadcity"  method="loadcity" class="roseindia.action.user.RegisterUser" >
        <result name="input" type="json" />
    </action>
</package>



回答2:


The validation interceptor might return an INPUT result if you are doing POST request. Usually you are done with adding an "input" result to the action configuration, but as far as you return a "json" result, you can exclude this action from validation or check the result type or status code returned to the caller to handle the content.




回答3:


Your XML node result should have an attribute name with the value of "input" as this is what you are returning.

So your struts.xml should look:

<package name="ajax" extends="json-default" >
    <action name="loadcity"  method="loadcity" class="roseindia.action.user.RegisterUser" >
        <result name="input" type="json" />
    </action>
</package>

edited:

Another error could be:

You are getting a validation or type conversion exception, so it looks for the "input" result.

Fix the validation/type conversion exception.

source: struts 2 json plugin throws error no result type is defined



来源:https://stackoverflow.com/questions/15119106/no-result-defined-for-action-class-and-result-input

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!