IDEA上servlet的创建和部署
伪代码流程 ----> 继承HttpServlet -----> 重写init,doGet,destory
使用WebServlet注解部署到tomcat容器
使用注解部署可以免去web.xml里配置

@WebServlet(name = "index",value = "/index")
public class MyServlet extends HttpServlet {
private String message;
@Override
public void init() throws ServletException {
message = "Hello index";
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setContentType("text/html");
PrintWriter out = resp.getWriter();
out.println("<h1>" + message + "</h1>");
}
@Override
public void destroy() {
super.destroy();
}
}
启动tomcat容器,访问/index 即可

上篇,如何一键在IDEA部署servlet web项目和tomcat容器
https://www.cnblogs.com/24cuo/p/16524258.html

浙公网安备 33010602011771号