取得除URI以前的路径,如:http://conkeyn.javaeye.com/

public String getServerPath(HttpServletRequest request) {
		String s = request.getScheme() + "://" + request.getServerName();
		if (request.getServerPort() != 80) {
			s += ":" + request.getServerPort();
		}
		if (StringUtils.isNotBlank(request.getContextPath())) {
			s += request.getContextPath();
		}
		return s;
	}

访问URL为:

 http://conkeyn.iteye.com/?s=dd&x=ss

返回:

 http://conkeyn.iteye.com

 

注意不包括“/?s=dd&x=ss”前面的"/"

你可能感兴趣的:(java)