How to get request URI without context path?

前端 未结 7 1080
时光说笑
时光说笑 2020-12-22 15:21

The Method request.getRequestURI() returns URI with context path.

For example, if the base URL of an application is http://localhost:8080/myapp/ (i.e.

7条回答
  •  孤城傲影
    2020-12-22 15:57

    A way to do this is to rest the servelet context path from request URI.

    String p = request.getRequestURI();
    String cp = getServletContext().getContextPath();
    
    if (p.startsWith(cp)) {
      String.err.println(p.substring(cp.length());
    }
    

    Read here .

提交回复
热议问题