You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.9 KiB
61 lines
1.9 KiB
3 years ago
|
package com.fr.plugin.bsSSO.utils;
|
||
|
|
||
|
import com.fr.json.JSONObject;
|
||
|
import com.fr.log.FineLoggerFactory;
|
||
|
import com.fr.web.utils.WebUtils;
|
||
|
|
||
|
import javax.servlet.http.HttpServletResponse;
|
||
|
import java.io.PrintWriter;
|
||
|
|
||
|
public class ResponseUtils {
|
||
|
private static final int SUCCESS = 200;
|
||
|
private static final int FAILED = -1;
|
||
|
|
||
|
public static void successResponse(HttpServletResponse res, String body) {
|
||
|
response(res, body, SUCCESS);
|
||
|
}
|
||
|
|
||
|
public static void failedResponse(HttpServletResponse res, String body) {
|
||
|
response(res, body, FAILED);
|
||
|
}
|
||
|
|
||
|
private static void response(HttpServletResponse res, String body, int code) {
|
||
|
JSONObject object = new JSONObject();
|
||
|
PrintWriter pw;
|
||
|
try {
|
||
|
object.put("code", code);
|
||
|
object.put("data", body);
|
||
|
pw = WebUtils.createPrintWriter(res);
|
||
|
} catch (Exception e) {
|
||
|
FineLoggerFactory.getLogger().info(e.getMessage());
|
||
|
return;
|
||
|
}
|
||
|
res.setContentType("application/json;charset=utf-8");
|
||
|
String result = object.toString();
|
||
|
pw.println(result);
|
||
|
pw.flush();
|
||
|
pw.close();
|
||
|
}
|
||
|
|
||
|
public static void response(HttpServletResponse res, String msg, String code,String data,String result2) {
|
||
|
JSONObject object = new JSONObject();
|
||
|
PrintWriter pw;
|
||
|
try {
|
||
|
object.put("status", code);
|
||
|
object.put("msg", msg);
|
||
|
object.put("data", data);
|
||
|
object.put("result", result2);
|
||
|
FRUtils.FRLogInfo("result " + object.toString());
|
||
|
pw = WebUtils.createPrintWriter(res);
|
||
|
} catch (Exception e) {
|
||
|
FineLoggerFactory.getLogger().info(e.getMessage());
|
||
|
return;
|
||
|
}
|
||
|
res.setContentType("application/json;charset=utf-8");
|
||
|
String result = object.toString();
|
||
|
pw.println(result);
|
||
|
pw.flush();
|
||
|
pw.close();
|
||
|
}
|
||
|
}
|