The solution that action in struts 2 can’t return JSON after implementing modelDriven

Time:2021-4-13

Copy codeThe code is as follows:
public class DeviceAction extends AbstractAction implements ModelDriven<Device> {
    private static Log log = LogFactory.getLog(DeviceAction.class);
Private device device = new device(); / / can only JSON model driven beans
Private string result; / / unable to return the JSON value of result

   
    public String getResult(){
        return result;
    }
    public void setResult(String result){
        this.result=result
    }
    public DeviceDTO getModel() {
        return device;
    }
    public Device getDevice() {
        return device;
    }
    public void setDevice(Device device) {
        this.device = device;
    }
}            

XML configuration:

Copy codeThe code is as follows:
<action name=”queryPu”
           
            method=”queryPu”>
            <interceptor-ref name=”isLogin”></interceptor-ref>
            <result type=”json“>
                <param name=”includeProperties”>
                    resultCode
                </param>
            </result>
        </action>

terms of settlement:

Copy codeThe code is as follows:
<action name=”queryPu”
           
            method=”queryPu”>
            <interceptor-ref name=”isLogin”></interceptor-ref>
            <result type=”json”>
                <param name=”root”>action</param>
                <param name=”includeProperties”>
                    resultCode
                </param>
            </result>
        </action>

Recommended Today

Review of SQL Sever basic command

catalogue preface Installation of virtual machine Commands and operations Basic command syntax Case sensitive SQL keyword and function name Column and Index Names alias Too long to see? Space Database connection Connection of SSMS Connection of command line Database operation establish delete constraint integrity constraint Common constraints NOT NULL UNIQUE PRIMARY KEY FOREIGN KEY DEFAULT […]