1. 程式人生 > >javaweb獲取訪問路徑、域名、專案名、

javaweb獲取訪問路徑、域名、專案名、

 HttpServletResponse response = ServletActionContext.getResponse();
        HttpServletRequest request = ServletActionContext.getRequest();
String url = request.getScheme()+"://"+ request.getServerName()+request.getRequestURI()+"?"+request.getQueryString();
System.out.println("獲取全路徑(協議型別://域名/專案名/名稱空間/action名稱?其他引數)url="+url);
String url2=request.getScheme()+"://"+ request.getServerName();//+request.getRequestURI();
System.out.println("協議名://域名="+url2);


System.out.println("獲取專案名="+request.getContextPath());
System.out.println("獲取引數="+request.getQueryString());
System.out.println("獲取全路徑="+request.getRequestURL());
request.getSession().getServletContext().getRealPath("/");//獲取web專案的路徑
this.getClass().getResource("/").getPath()//獲取類的當前目錄