企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
![](https://box.kancloud.cn/33de5fd7d0e5041bb6452107d8bcc4a0_491x243.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; 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)); }*/ //获取请求参数 String name = req.getParameter("name"); String passWord = req.getParameter("passWord"); System.out.println("用户名:"+name); System.out.println("密码:"+passWord); } @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { System.out.println("接收到post请求"); } } ~~~ get.html ~~~ <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> </body> <center> <h2>发起HTTP get请求</h2> <form action="hi" method="get"> <p>账号: <input type="text" name="name" /></p> <p>密码: <input type="text" name="passWord" /></p> <input type="submit" value="提交" /> </form> </center> </html> ~~~ ![](https://box.kancloud.cn/e48e3bf8c3866c89d38be683f9666f79_1026x230.png) 结果: ![](https://box.kancloud.cn/a5ccf7fb038d22c0ff12206fc5459d7b_600x89.png)