-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRequestDemo01.java
More file actions
64 lines (52 loc) · 2.21 KB
/
Copy pathRequestDemo01.java
File metadata and controls
64 lines (52 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package request;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
* @author : CodeWater
* @create :2022-03-13-16:20
* @Function Description :
* 演示Request对象获取请求行
*/
@WebServlet("/requestDemo01")
public class RequestDemo01 extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
/*
1. 获取请求方式 :GET
* String getMethod()
2. (*)获取虚拟目录:/day14
* String getContextPath()
3. 获取Servlet路径: /requestDemo1
* String getServletPath()
4. 获取get方式请求参数:name=zhangsan:输入地址后要加?name=zhangsan
* String getQueryString()
5. (*)获取请求URI:/day14/demo1
* String getRequestURI(): /day14/requestDemo1
* StringBuffer getRequestURL() :http://localhost/day14/requestDemo1
6. 获取协议及版本:HTTP/1.1
* String getProtocol()
7. 获取客户机的IP地址:
* String getRemoteAddr()
*/
String method = request.getMethod();
System.out.println(method);
String contextPath = request.getContextPath();
System.out.println(contextPath);
String servletPath = request.getServletPath();
System.out.println(servletPath);
String queryString = request.getQueryString();
System.out.println(queryString);
String requestURI = request.getRequestURI();
StringBuffer requestURL = request.getRequestURL();
System.out.println(requestURI + "I-------L" + requestURL);
String protocol = request.getProtocol();
System.out.println(protocol);
String remoteAddr = request.getRemoteAddr();
System.out.println(remoteAddr);
}
}