Commit 673dae1d authored by zengtianlai3's avatar zengtianlai3

解决跨域乱码

parent a482b39a
......@@ -29,22 +29,25 @@ public class JwtFilter implements Filter {
final HttpServletRequest request = (HttpServletRequest) servletRequest;
final HttpServletResponse response = (HttpServletResponse) servletResponse;
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=utf-8");
response.setHeader("Access-Control-Allow-Origin","*");
response.setHeader("Access-Control-Allow-Credentials","true");
response.setHeader("Access-Control-Allow-Headers", "Content-Type,Content-Length, Authorization, Accept,X-Requested-With,X-App-Id, X-Token");
response.setHeader("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
//获取header里的token
String token = request.getHeader("authorization");
if ("OPTIONS".equals(request.getMethod())) { //除了 OPTIONS请求以外, 其它请求应该被JWT检查
//除了 OPTIONS请求以外, 其它请求应该被JWT检查
if ("OPTIONS".equals(request.getMethod())) {
response.setStatus(HttpServletResponse.SC_OK);
filterChain.doFilter(request, response);
} else {
if (token == null) {
String resultStr = JSON.toJSONString(ResResult.fail().msg("认证信息不能为空"));
response.getWriter().write(resultStr);
// response.getWriter().write("miss token");
return;
}
}
// Map<String, Claim> userData = JwtUtil.verifyToken(token);
DecodedJWT jwt = JwtUtil.verifyToken(token);
if(jwt==null){
String resultStr = JSON.toJSONString(ResResult.fail().msg("认证信息非法"));
......@@ -53,7 +56,6 @@ public class JwtFilter implements Filter {
}else{
Map<String, Claim> userData = jwt.getClaims();
if (userData == null) {
// response.getWriter().write("token is illegal");
String resultStr = JSON.toJSONString(ResResult.fail().msg("认证信息非法"));
response.getWriter().write(resultStr);
return;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment