1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| public class JSONResult extends StrutsResultSupport implements Result {
private static final long serialVersionUID = -8387567866065570225L;
@Override
protected void doExecute(String finalLocation, ActionInvocation invocation)
throws Exception {
try {
ValueStack valueStack = invocation.getStack();
Object jsonModel = valueStack.findValue("jsonModel");
if (jsonModel != null) {
ServletActionContext.getResponse().setContentType("text/plain");
ServletActionContext.getResponse().setCharacterEncoding("UTF-8");
PrintWriter responseStream = ServletActionContext.getResponse().getWriter();
JSONSerializer serializer = new JSONSerializer().exclude("class").include("rows");
if (finalLocation != null) {
serializer.include(finalLocation);
}
responseStream.println(serializer.serialize(jsonModel));
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} |
Partager