Why I am getting 500 (Internal Server Error) in Struts 2 while sending data using Ajax?

2.1k views Asked by At

I am trying to develop a struts 2 web application and sending data via Ajax but the console show an 500 (Internal Server Error). I have tried a log but no solution found. But the operation performed successfully in back end means my data is updated but the output is Internal Server Error Here is my code..

ajax function

   function revertIbcData(mydata) {
            var paNo = $(mydata).attr("rollNo");
            var viNo = $(mydata).attr("idNo");
            alert(paNo + " " + viNo);

            $.ajax({
                type: 'GET',
                contentType: 'application/json;  charset=utf-8',
                dataType: "json",
                url: "revert.do",
                data: {rollNo: paNo, idNo: viNo},
                success: function (data) {
                    alert(data.msg);
                },
                error: function (abc, cba, errorThrown) {
                    alert('Error: ' + errorThrown);
                }
            });
        }

action code

    public String revertData() {
    try {
        conn = connect.getConnection();
        ibcDAO.revertIbcProcessDetail(conn, rollNo, idNo);
        msg = "Detail of " + rollNo + " and " + idNo + " reverted successfully.";
        System.out.println(msg);
        return "success";
    } catch (Exception e) {
        e.printStackTrace();
        return "success";
    } 
}

and struts.xml is

    <action name="revert"  class="pac.ProcessAction" method="revertData">
        <result name="success" type="json"></result>                   
    </action>      
2

There are 2 answers

0
Nabarun Dey On BEST ANSWER

Try this:

<action name="revert"  class="pac.ProcessAction" method="revertData">
       <result name="success" type="json">
         <param name="root">jsonString</param>
       </result>                   
    </action>   

Here "jsonString" should be a class level variable.

0
mystdeim On

Set log inside revertData to determine where error occurs, and check this article: http://tech.learnerandtutor.com/read-json-object-from-struts-2-action-by-jquery-ajax/