首页 > 技术文章 > jsp获取服务端的访问信息

wala-wo 2014-05-29 08:49 原文

 

  •  获取服务端访问信息   
    public static String getUrl(HttpServletRequest request){      
        String url = "";  
          
        if(request != null){  
            String scheme       = request.getScheme();  
            String host         = request.getLocalAddr();  
            int post        = request.getLocalPort();  
            String contextPath  = request.getContextPath();  
                      
                      
            url = scheme + "://" + host + ":" + String.valueOf(post) + "/" + contextPath + "/";   
        }  
        return url;   
    }  




推荐阅读