IDEA与tomcat相关配置:
1.IDEA会为每一个tomcat部署的项目单独建立一份配置文件
查看控制台log:Using CATALINA_BASE: "C:\Users\齐浩宽\AppData\Local\JetBrains\IntelliJIdea2022.1\tomcat\7453b0c5-b81d-47a7-a3bb-0b9f90032381"
2.工作空间项目和tomcat部署的web项目
tomcat真正访问的是 "tomcat部署的web项目", "tomcat部署的web项目"对应着 "工作空间项目"的web目录下的所有资源
WEB-INF目录下的资源不能直接被浏览器访问
3.断电调试:使用小虫子启动 dubug 启动
servlet_体系结构:
Servlet - - 接口
|
GenericServlet - - 抽象类
|
HttpServlet - - 抽象类
GenericServlet:将Servlet接口中其他的方法做了默认空实现,只将Service()方法作为抽象
将来定义Servlet类时,可以继承GenericServlet,实现service()方法即可
@WebServlet("/demo4") public class ServletDemo4 extends GenericServlet { @Override public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException { System.out.println("demo4..."); } }
HttpServlet:对http协议的一种封装,简化操作
1.定义类继承HttpServlet
2.复写doGet/doPost
@WebServlet("/demo5") public class ServletDemo5 extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { System.out.println("doGet..."); } @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { System.out.println("doPost..."); } }
login.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <form action="demo5" method="post"> <input name="username"> <input type="submit" value="提交"> </form> </body> </html>
标签:web,ServletException,tomcat,GenericServlet,IDEA,HttpServlet,servlet From: https://www.cnblogs.com/hungui/p/16960371.html