How to get only part of URL from HttpServletRequest?

前端 未结 5 1956
花落未央
花落未央 2020-12-31 02:05

From the following URL I need to get (http://localhost:9090/dts) alone.
That is I need to remove (documents/savedoc) (OR)
need to get on

5条回答
  •  一个人的身影
    2020-12-31 02:38

    AFAIK for this there is no API provided method, need to customization.

    String serverName = request.getServerName();
    int portNumber = request.getServerPort();
    String contextPath = request.getContextPath();
    

    // try this

    System.out.println(serverName + ":" +portNumber + contextPath );
    

提交回复
热议问题