你好前辈,我你的框架上,在webmvaConfigurer中加入了一个过滤器
AppTokenCheckFilter
这个类的详情如下:
/** 过滤器 */
public class AppTokenCheckFilter extends OncePerRequestFilter {
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
System.out.println("AppTokenCheckFilter++++++: "+request.getPathInfo());
try {
if(!WebConstant.PASS_REQUEST.contains(request.getPathInfo())) {
String token = request.getHeader("Authorization");
//检查jwt令牌, 如果令牌不合法或者过期, 里面会直接抛出异常, 下面的catch部分会直接返回
Map<String,Object> result = JwtUtil.validateToken(token);
request.setAttribute("uId",result.get("uId"));
request.setAttribute("phone",result.get("phone"));
}
} catch (Exception e) {
PathCheckMsgUtil.writeMsgToPage(request, response, ResponseVoResultCode.CODE_AUTHORITY, "您的身份验证已过期, 请重新登录", "app no token");
return;
}
//如果jwt令牌通过了检测, 那么就把request传递给后面的RESTful api
filterChain.doFilter(request, response);
}
}
当有请求进来后,通过request.getPathInfo()获取 路径,一直是null,不明白哪有问题,希望前辈能指点一下?
先用这个试试看 String path=request.getRealPath("/");