package cn.itcast.web.request;
import jdk.nashorn.internal.objects.AccessorPropertyDescriptor;
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;
//1.获取请求方式:GET
// String getMethod()
// 2.()获取虚拟目录
// String getContextPath()
// 3. 获取Servlet路径:/demo1
// String getServletPath()
// 4.获取get方式请求参数:name=zhangsan&age=12 question?使用html提交标签可以将数据上传
// String getQueryString()
// 5.()获取请求的 uri:统一资源标识符 URL:统一资源定位符
// getRequestURI();
// String getRequestURL();
// 6.获取协议以及版本:HTTP/1.1
// String getProtocol()
// 7.获取客户端的ip地址
// String getRemoteAddr();
// */
@WebServlet("/requestdemo1")
public class requestdemo1 extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//1获取请求方式:get
String method = req.getMethod();
System.out.println(method);
//2获取虚拟目录
String contextPath = req.getContextPath();
System.out.println(contextPath);
//3获取servlet路径
String servletPath = req.getServletPath();
System.out.println(servletPath);
//4获取get方式请求参数
String queryString = req.getQueryString();
System.out.println(queryString);
//5获取uri,url
String requestURI = req.getRequestURI();
StringBuffer requestURL = req.getRequestURL();
System.out.println(requestURI);
System.out.println(requestURL);
//6获取协议以及版本
String protocol = req.getProtocol();
System.out.println(protocol);
//7获取客户机的ip地址
String remoteAddr = req.getRemoteAddr();
System.out.println(remoteAddr);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
}
}