spring mvc中獲取請求URL

Franson發表於2018-03-08

String baseUrl=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort+request.getContextPath()+"/";

得到形如http://www.baidu.com:8080/xxx

從HttpServletRequest獲取:
request.getRemoteAddr()獲取ip
request.getRemotePort()獲取埠號
request.getServletPath()獲取請求地址

相關文章