这段视频没有声音,我大概猜测一下
在 src / main / java 目录下创建一个 Servlet。名字随意
里面的代码应该如下:
package com.tootaio.servlet;
import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse;
@WebServlet("/LoginServlet") public class LoginServlet extends HttpServlet { private static final long serialVersionUID = 1L; public LoginServlet() { super(); }
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.getWriter().append("Served at: ").append(request.getContextPath()); }
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); }
}
|
其中,@WebServlet()
是当前 servlet 的路径(网址路径)
doGet 是获取 HttpGet 时该怎么处理
doPost 是遇到 HttpPost 时该怎么处理