💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
![](https://box.kancloud.cn/b9a49a8fb9f0a6989627d7a27e8a142d_487x251.png) HelloServelt.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.io.PrintWriter; 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); String result="恭喜您登录成功"; //方法1-getOutputStream(); /*ServletOutputStream OutputStream =resp.getOutputStream(); OutputStream.write(result.getBytes());*/ //方法2-getWriter(); resp.setContentType("text/html;charset=utf-8");//指定输出编码 PrintWriter writer = resp.getWriter(); writer.write(result);//输出的就是字符流 } @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { System.out.println("接收到post请求"); } } ~~~ ![](https://box.kancloud.cn/160ad93b8f57ec01834fb09026656987_735x117.png)