IDEA与tomcat相关配置
IDEA会为每一个tomcat部署的项目单独建立一份配置文件
查看控制台的log:"C:\Users\drm\AppData\Local\JetBrains\IntelliJIdea2022.1\tomcat\5c324c45-dc07-4b59-88aa-9c3db21cbd83"
工作空间项目和tomcat部署的web项目
tomcat真正访问的事tomcat部署的web项目。tomcat部署的web对应着工作空间项目的web目录的所有资源
WEB-INF目录小的资源不能被浏览器直接访问
断点调试:使用小虫子启动DuBug启动
Servlet体系结构
Servlet的体系结构
Servlet--接口
GenericServlet--抽象类
httpServlet--抽象类
GenericServlet:将Servlet接口中其他的方法做了默认空实现,只将service()方法作为抽象
将来定义Servlet类时,可以继承GenericServlet,实现service()方法即可
HttpServlet:对http协议的一种封装,简化操作
1.定义类继承HttpServlet
2.复写doGet/doPost方法
Servlet相关配置
1.urlpartten:Servlet访问路径
1.一个Servlet可以定义多个访问路径:@WebServlet({"/d4","/dd4","/ddd4"})
2. 路径定义规则:
1. /xxx:路径匹配
2. /xxx/xxx:多层路径,目录结构
3. *.do:扩展名匹配
package com.example.day_12_servlet; import javax.servlet.GenericServlet; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.annotation.WebServlet; import java.io.IOException; @WebServlet("/demo2") public class ServletDemo2 extends GenericServlet { @Override public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException { System.out.println("demo2"); } }
package com.example.day_12_servlet; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; @WebServlet("/demo3") public class ServletDemo3 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"); } }标签:ServletException,tomcat,Servlet,IDEA,import,servlet,javax From: https://www.cnblogs.com/wsfj/p/17085742.html