I am trying to build a web application using Struts 2 and jQuery.
On change of a dropdown list, I need to fetch the details from the database. In my struts.xml
configuration, I have defined the method and action as follows:
<result name="addressChange">
<param name="root">requestBean</param>
</result>
When I executed the application after making a change in all the respective places, the request was passed on to the Action
class and DAO methods and the control is returned to screen successfully. But the data returned was not available on the screen and I was getting an error message that:
the url ... 404 not found (anonymous function) ajax in jquery.
Since I had some other ajax call, I compared them and found out that the result type is missing in the struts.xml and then I changed it likewise. Its working fine now.
<result name="addressForBrigade" type="json">
<param name="root">requestBean</param>
</result>
Questions are:
- How come Struts identify it as JSON object and how does it cover it to the POJO?
- When should we use the result type as JSON in Struts 2?
- Can we use other result types?
- Should we need to use the result type as JSON whenever there is an AJAX call?