如何在ajax中调用Struts2 Action方法?

Jot*_*thi 2 ajax struts2

如何在ajax中调用Struts2 Action方法.现在我工作调用servlet.is有可能吗?如果有的话请分享.

bad*_*ato 9

更新struts.xmlas

<package name="prjajax" namespace="/" extends="json-default">

<result-types>
    <result-type name="json" class="org.apache.struts2.json.JSONResult" />
</result-types>
<action name="AJAXAction" class="com.demo.sd.prj.ui.actions.AJAXAction" method="myMethod">
    <result name="success" type="json" />
</action>
Run Code Online (Sandbox Code Playgroud)

jQuery code:

$.ajax({
    url: "AJAXAction",
    type: "POST",
    data: {data: $('#txtbox').val()},
    dataType: "json",
    error: function(XMLHttpRequest, textStatus, errorThrown){
        alert('Error ' + textStatus);
        alert(errorThrown);
        alert(XMLHttpRequest.responseText);
    },
    success: function(data){         
        alert('SUCCESS');

       }
});
Run Code Online (Sandbox Code Playgroud)