学习如何获取请求行, 请求头,请求体。
String method = request.getMethod();
System.out.println(method);
StringBuffer requestURL = request.getRequestURL();
String requestURI = request.getRequestURI();
System.out.println(requestURL);
System.out.println(requestURI);
String contextPath = request.getContextPath();
System.out.println(contextPath);
String queryString = request.getQueryString();
System.out.println(queryString);
// 获取所有请求头名称
Enumeration<String> headerNames = request.getHeaderNames();
// 取出所有请求头名称 并打印
while(headerNames.hasMoreElements()) {
System.out.println(headerNames.nextElement());
}
String header = request.getHeader("referer");
System.out.println(header);
// 获取所有请求头名称
Enumeration<String> headerNames = request.getHeaderNames();
// 取出所有请求头名称 并打印
while(headerNames.hasMoreElements()) {
String name = headerNames.nextElement();
String value = request.getHeader(name);
System.out.println(name +" : "+value);
}
告诉服务器我是从哪个页面链接过来的
原文:https://www.cnblogs.com/xzh0717/p/10651938.html