知识点
前言
一、Servlet
面试重点
二、使用
@WebServlet("/req-info")
public class GetRequestInfoServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// 我们只做打印(在 IDEA 的控制台上看到显示),不做响应(浏览器看不到,白屏)
// 1. 请求方法
String method = req.getMethod();
System.out.println("HTTP 方法: " + method);
System.out.println();
System.out.println();
String requestURI = req.getRequestURI();
System.out.println("requestURI: " + requestURI);
StringBuffer requestURL = req.getRequestURL();
System.out.println("requestURL: " + requestURL.toString());
String pathInfo = req.getPathInfo();
System.out.println("pathInfo: " + pathInfo);
String contextPath = req.getContextPath();
System.out.println("contextPath: " + contextPath);
String servletPath = req.getServletPath();
System.out.println("servletPath: " + servletPath);
String pathTranslated = req.getPathTranslated();
System.out.println("pathTranslated: " + pathTranslated);
String queryString = req.getQueryString();
System.out.println("queryString: " + queryString);
System.out.println();
System.out.println();
String serverName = req.