POST request to Struts2 with REST plugin not receiving response

前端 未结 3 1027
终归单人心
终归单人心 2021-01-12 10:22

I have a struts2 application which uses the struts2-rest-plugin v.2.2.3.

Everything is working great when it comes to the routing of the requests to the actions and

3条回答
  •  失恋的感觉
    2021-01-12 11:11

    I've used struts actions with mixed result types in the past, returning json, xml, and tiles for instance. I'm not sure if it's the recommended way to do it but it requires some configuration using struts.xml even though conventions are being used. Maybe you've already done this, not sure there isn't enough info provided to tell.

    Struts.xml settings:

    
    
    
        
            
            
        
    
        ....
    
    

    I have setup the extra result types to be used on specific actions later. In the action class you can then setup your result types by action or method.

    Action Class:

    @Results({
        @Result(name = "JsonSuccess", type = "json"),
        @Result(name = "success", type = "tiles", location = "/tickets.tiles")
    })
    
    public class EventController extends RestActionSupport implements ModelDriven{
         ...
    }
    

    Something else to note about json results, I've noticed that when I have a serializable object being returned as a result, if that object contains other complex objects with a getter/setter that returns the embedded object, I will often receive an empty result or no result. I often end up writing json wrapper objects to use for my json results with getters/setters that only return java types (String, int, Boolean, etc) and not the embedded objects. I think that've solved this using delegate getters/setters but I'll have to go back and look at some old code.

提交回复
热议问题