ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
![](https://box.kancloud.cn/5bd0e65bd1cd135a2da076d7ecfa7c42_483x128.png) ![](https://box.kancloud.cn/9d67cdc29251d4b5ff65781d9e8e6441_485x347.png) ![](https://box.kancloud.cn/cf1344d5db8a86fc598622549cfdbeaa_488x299.png) HelloServlet.java ~~~ package zyw.servlet; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.Enumeration; public class HelloServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { //System.out.println("接收到get请求"); //获取请求行 /* System.out.println("请求方式:"+req.getMethod()); System.out.println("URI:"+req.getRequestURI()); System.out.println("发出请求客户端IP地址:"+req.getRemoteAddr()); System.out.println("服务点接收请求的IP地址:"+req.getLocalAddr()); System.out.println("访问客户端的端口号:"+req.getRemotePort()); System.out.println("web应用路径:"+req.getContextPath()); System.out.println("http协议和版本:"+req.getProtocol());*/ //获取请求头 // Enumeration枚举类型 Enumeration<String> headerNames = req.getHeaderNames();//自动补全变量名称 : Ctrl + Alt + v while (headerNames.hasMoreElements()){ String element = headerNames.nextElement(); System.out.println(element+":"+req.getHeader(element)); } } @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { System.out.println("接收到post请求"); } } ~~~ 获取请求行的结果 ![](https://box.kancloud.cn/d47f7817dd452859a0e06a40746c9a01_408x293.png) 获取请求头的结果 ![](https://box.kancloud.cn/a990196569823970fdd3803ab70509dd_1016x208.png)