星期三

发布时间 2023-09-27 14:20:30作者: umiQa

关于servlet

servlet用于处理前端的请求并反应,实现前端与数据库的对接

创建一个类继承HttpServlet类

public class ServletDemo3 extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        System.out.println("haha");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        System.out.println("ee");
        doGet(req,resp);
    }

}
get和post分别是接到请求的两种方法,方法中的request对象和response对象分别用于请求和响应