How to get request URI without context path?

前端 未结 7 1024
时光说笑
时光说笑 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 16:10

    getPathInfo() sometimes return null. In documentation HttpServletRequest

    This method returns null if there was no extra path information.

    I need get path to file without context path in Filter and getPathInfo() return me null. So I use another method: httpRequest.getServletPath()

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
    {
        HttpServletRequest httpRequest = (HttpServletRequest) request;
        HttpServletResponse httpResponse = (HttpServletResponse) response;
    
        String newPath = parsePathToFile(httpRequest.getServletPath());
        ...
    
    }
    
    0 讨论(0)
提交回复
热议问题