package com.lightinit.hsdataportal.common;

import java.io.PrintWriter;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;
import org.codehaus.jackson.map.ObjectMapper;
/**
 * Created by Mr.Yao on 2017/11/8.
 */
public class ShiroFilterUtils {
    private static ObjectMapper objectMapper = new  ObjectMapper();
    public static boolean isAjax(ServletRequest request){
        return "XMLHttpRequest".equalsIgnoreCase(((HttpServletRequest) request).getHeader("X-Requested-With"));
    }
    public static void out(ServletResponse response, Map<String, String> resultMap){
        PrintWriter out = null;
        try {
//            response.setCharacterEncoding("UTF-8");
            out = response.getWriter();
            out.println(objectMapper.writeValueAsString(resultMap));
        } catch (Exception e) {
            e.printStackTrace();
        }finally{
            if(null != out){
                out.flush();
                out.close();
            }
        }
    }
}
