过滤器中的request.getPathInfo()一直返回null

来源:12-1 项目2.0功能总览

qq_宝慕林3207953

2020-03-07

你好前辈,我在你的springboot框架上,增加了一个过滤器
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,不明白哪有问题,希望前辈能指点一下?

写回答

1回答

翔仔

2020-03-09

同学好,看看这篇链接有帮助不 https://blog.csdn.net/baidu_35772611/article/details/52289509


0
4
翔仔
回复
qq_宝慕林3207953
同学好,主要是这样做拦截的话这个方法是获取不到路径的 试试 request.getServletPath() 看看是不是需要的 https://www.ktanx.com/blog/p/3551
2020-03-10
共4条回复

Java双版本(SSM到SpringBoot)校园商铺全栈开发

SSM商铺V1.0,解决毕设痛点;SpringBoot商铺V2.0,满足工作刚需

5127 学习 · 8149 问题

查看课程