0

I'm trying to have an Ajax call in my Struts 2 project in Netbeans, and I'm having issues getting it to work that seem to have to do with libraries. First of all, the only combination I've found that works at all is to use the current (2.5.22) JSON plugin with the Struts 2.3 core libraries; if I use the "correct" 2.3 version of the plugin, or if I use the 2.5 Struts libraries all around, I don't get any error messages, but I don't get any data either: none of the fields of the action class get populated. However, I can't get the return data back; instead I get an HTML-formatted 500 message saying "java.lang.NoClassDefFoundError: Could not initialize class org.apache.struts2.json.JSONResult" plus a ton of traceback after that. I can see perfectly well that this class is there in the JSON plugin jar. So my library list at present looks like this: library list

My struts.xml entry for the action in question is

        <action name="updateProductWorkforceAjax" class="prsm2.display.controller.SingleProductAjax"
            method="updateProductWorkforceAjax">
        <interceptor-ref name="json">                                                                                                              
            <param name="enableSMD">true</param>                                                                                                                                                                                     
        </interceptor-ref>                                                                                                                           
        <result type="json">
        </result>                                                                                                  
    </action>

and I am extending the json-default package.

The Ajax call looks like this:

              var arg = {dvList: dvlist,
                prodId : prodId,
                orgId : orgId,
                programYear : programYear,
                functionalArea : fa};
            
            $.ajax({
                data: arg,
                type: 'POST',
                dataType : 'json',
                url: 'updateProductWorkforceAjax',
                success: function(data) {
                    control.log(data);
                },
                error:function(result) {
                    var zz = result;
                }
            })

where all the variables folded into arg are strings. The action class has all the required getters and setters and appears to work fine-- after all if I use the inconsistent libraries, it gets data correctly.

I've tried using a complete set of libraries for one version, which will not run at all (the server won't even start).

If someone can tell me what libraries will work together for this, or what I'm doing wrong with the ones I have, I would appreciate it.

C Wingate
  • 1
  • 2
  • No, it doesn't work if you use different versions of libraries, servlets, JSP, Java, and I don't mind what else. You didn't clarify your problem related to code you have posted. [Here](https://stackoverflow.com/a/24479517/573032) you can find examples of Ajax requests. – Roman C Aug 27 '20 at 18:04
  • If it’s 2.5 that isn’t working showing the 2.3 stuff isn’t that helpful. Are you actually using SMD?! It doesn’t look like you want to be. – Dave Newton Aug 27 '20 at 21:40
  • Well, having fiddled with it a while. I've managed to get it to give me data in my action class using only 2.3.37 libraries, but it still fails to return data in the same manner. I've added some further info above. – C Wingate Aug 27 '20 at 22:15
  • I'm not using SMD but taking it out has no effect one way or the other. – C Wingate Aug 27 '20 at 22:17

0 Answers0