javaweb后台request获取项目名,端口号等

        

通过request获取域名,请求路径,端口号等

       HttpServletRequest request = getRequest();
        String scheme = request.getScheme();//http
        String serverName = request.getServerName();//localhost
        int serverPort = request.getServerPort();//8080
        String contextPath = request.getContextPath();//项目名
        String url = scheme+"://"+serverName+":"+serverPort+contextPath;//http://127.0.0.1:8080/test

 

你可能感兴趣的:(javaweb后台request获取项目名,端口号等)