posts - 397,comments - 0,views - 25332

概念

步骤
执行原理

生命周期
servlet3.0 注解配

servlet的体系结构

servlet --接

Genericservlet --抽象类

Httpservlet --抽象类

GenericServlet:将servlet接口中其他的方法做了默认空实现,只将service()方法作为抽浆

将来定义servlet类时,可以继承Genericservlet,实现service()方法即可

 

复制代码
@WebServlet("/demo1")

public class ServletDome2 extends GenericServlet {


    @Override
    public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
        System.out.println("sssssssss---------");
    }
}
复制代码

 

 

 

 

 

 

 

 

 

复制代码
@WebServlet("/demo3")

public class ServletDome3 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");
    }
}
复制代码
复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <form action="/demo3" method="post">
        <input name="username"><br>
        <input type="submit" value="提交">
    </form>
</body>
</html>
复制代码

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Servlet_urlpartten相关配置

Servlet相关配置

urlpartten:Servlet访问路径

  一个Servlet可以定义多个访问路径:(@WebServlet({"/d4","/dd4","/ddd4"}))

  路径定义规则:

    /xxx

    /xxx/xxx:多层路径,目录结构

    *.do

复制代码
//@WebServlet({"/d4","/dd4","/ddd4"})
//@WebServlet("/user/demo4")
//@WebServlet("/user/*")
//@WebServlet("/*")
@WebServlet("*.do")

public class ServletDome4 extends HttpServlet {

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

 

posted on   淤泥不染  阅读(19)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示