System.out.println(request.getMethod()); //请求方式
System.out.println(request.getRequestURI()); 虚拟路径
System.out.println(request.getQueryString()); 参数
System.out.println(request.getServletContext());
System.out.println(request.getRequestURL()); 完整url
System.out.println(request.getServletPath());servlet路径
System.out.println(request.getProtocol()); 协议
System.out.println(request.getCookies());
System.out.println(request.getSession());
System.out.println(request.getRemoteAddr());ip
GET
/ServerLetLearn/mygard3
null
org.apache.catalina.core.ApplicationContextFacade@4fc8e1d1
http://localhost/ServerLetLearn/mygard3
/mygard3
HTTP/1.1
[Ljavax.servlet.http.Cookie;@359b2ea5
org.apache.catalina.session.StandardSessionFacade@3d5597ae
0:0:0:0:0:0:0:1
、、遍历请求头
Enumeration<String> heardNames = request.getHeaderNames();
while (heardNames.hasMoreElements()){
String el = heardNames.nextElement();
System.out.println(request.getHeader(el));
}
、、字符流,只能读字符串
BufferedReader reader = request.getReader();
String line =null;
while ((line = reader.readLine()) != null){
System.out.println(line);
}
、、字节流,可以读所有的数据
ServletInputStream streamss = request.getInputStream();
String[] hobbies = req.getParameterValues("hobbies");
直接输入iter会自动关联出下面的这个循环
for (String hobby : hobbies) {
}
网友评论