xpublic class GlobalResponse {
public static final String CONTENT_TYPE = "Content-Type";
public static final String ACCESS_CONTROL_ALLOW_ORIGIN = "Access-Control-Allow-Origin";
public static final String ACCESS_CONTROL_ALLOW_METHODS = "Access-Control-Allow-Methods";
public static final String ACCESS_CONTROL_ALLOW_HEADERS = "Access-Control-Allow-Headers";
public static void writeResponse(HttpServletResponse response, Result result){
response.setHeader(CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE);
response.setHeader(ACCESS_CONTROL_ALLOW_ORIGIN, "http://localhost:5173/");
response.setHeader(ACCESS_CONTROL_ALLOW_METHODS, "*");
response.setHeader(ACCESS_CONTROL_ALLOW_HEADERS, "*");
String json= JSONObject.toJSONString(result);
try {
response.getWriter().println(json);
response.getWriter().flush();
response.getWriter().close();
} catch (IOException e) {
e.printStackTrace();
}
}
}