In a struts2 application I am calling a Ajax request in and write a string directly to the response as below and return null
in the execute method of the action.
ServeletActionContext.getResponse().getOutputStream().print("sample string");
return null;
In struts.xml
I have the below declaration, (below is how the application declares the actions with result types which are working fine. In my case since I don't need result to invoke a JSP or another action, I did not add the result tag)
<action name="controller" class="controller">
And I map the section class in the application-context.xml
<bean id="controller" class="com.test.ControllerAction" scope="prototype">
Then I have the ajax call as below,
$.ajax({url:"/root/me/controller.action",success:function(result){
alert(result);
}});
But the problem is in above instead of alerting the "sample string"
which I wrote for the response, it alerts the whole JSP page where the above Ajax call resides. What am I missing here?