String contextPath = request.getContextPath();
String headerReferer =request.getHeader("Referer");
String domain = headerReferer.substring(0,headerReferer.indexOf(contextPath)+contextPath.length()+1).
replaceAll("http://", "").replaceAll(contextPath, "").replaceAll("/", "");
打印结果:
contextPath : /trade
headerReferer : http://172.16.1.103:8080/trade/index.jsp
domain : 172.16.1.103:8080