Get Servlet information about the client from the request

getRequestURL

		StringBuffer url = request.getRequestURL();
		System.out.println(url);
		
		String url1 = request.getRequestURI();
		System.out.println(url1);

console

http://localhost/ServletLifeTime/hps
/ServletLifeTime/hps

getContextPath

String path = request.getContextPath();
		System.out.println(path);

console

/ServletLifeTime

getServletPath和getPathInfo

The former exact path, which path fuzzy (wildcard path)

String servletPath = request.getServletPath();
		String info = request.getPathInfo();
		System.out.println(servletPath+":"+info);

console

/hps:null

getRemoteAddr

Obtain client ip

String ClientIp = request.getRemoteAddr();
		System.out.println(ClientIp);

console

0:0:0:0:0:0:0:1
Published 114 original articles · won praise 8 · views 5492

Guess you like

Origin blog.csdn.net/OVO_LQ_Start/article/details/104717420