Request获取url信息以及url带的参数

通过url访问服务器可以得出连接本服务器所有机器的ip以及端口等信息

在浏览器上输入:

http://192.168.191.1:8080/HttpServletRequestTest/servlet/HttpServletRequestTest?a=1&b=2

可以获得访问服务器所有设备的ip以及端口

以下是输出的日志:

Request获取url信息以及url带的参数_第1张图片

java代码如下:

System.out.println("getRequestURL: "+request.getRequestURL());
         System.out.println("getRequestURI: "+request.getRequestURI());
         System.out.println("getQueryString: "+request.getQueryString());
         System.out.println("getRemoteAddr: "+request.getRemoteAddr());
         System.out.println("getRemoteHost: "+request.getRemoteHost());
         System.out.println("getRemotePort: "+request.getRemotePort());
         System.out.println("getRemoteUser: "+request.getRemoteUser());
         System.out.println("getLocalAddr: "+request.getLocalAddr());
         System.out.println("getLocalName: "+request.getLocalName());
         System.out.println("getLocalPort: "+request.getLocalPort());
         System.out.println("getMethod: "+request.getMethod());
         System.out.println("-------request.getParamterMap()-------");
         //得到请求的参数Map,注意map的value是String数组类型
         Map map = request.getParameterMap();
         Set keySet = map.keySet();
         for (String key : keySet) {
			String[] values = (String[]) map.get(key);
			for (String value : values) {
				System.out.println(key+"="+value);
			}
		 }
         System.out.println("--------request.getHeader()--------");
         //得到请求头的name集合
         Enumeration em = request.getHeaderNames();
         while (em.hasMoreElements()) {
			String name = (String) em.nextElement();
			String value = request.getHeader(name);
			System.out.println(name+"="+value);
		}
源代码地址 点击打开链接

你可能感兴趣的:(Request获取url信息以及url带的参数)