| | |
| | | request.setCharacterEncoding("UTF-8");
|
| | | response.setCharacterEncoding("UTF-8");
|
| | | response.setContentType("text/html;charset=utf-8");
|
| | | isAlowCrossDomain(response);
|
| | | isAlowCrossDomain(response,request);
|
| | | chain.doFilter(request, response);
|
| | |
|
| | | //检测跨域访问的请求
|
| | |
| | | response.setHeader("Access-Control-Allow-Methods", "GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS, PATCH");
|
| | | }
|
| | |
|
| | | /**
|
| | | * 允许跨域访问
|
| | | * @param response
|
| | | */
|
| | | public void isAlowCrossDomain(HttpServletResponse response,HttpServletRequest request){
|
| | | response.setHeader("Access-Control-Allow-Credentials","true"); //是否支持cookie跨
|
| | | response.setHeader("Access-Control-Allow-Origin", request.getHeader("Origin"));
|
| | | }
|
| | | |
| | | public static void main(String[] args) {
|
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
| | | System.out.println(sdf.format(new Date()));
|