Erlo

java servlet的执行流程

2018-10-18 07:58:46 发布   392 浏览  
页面报错/反馈
收藏 点赞

1、先附上代码如下

Servlet1.java
public class Servlet1 implements Servlet {
    @Override
    public void init(ServletConfig config) throws ServletException {

    }

    @Override
    public ServletConfig getServletConfig() {
        return null;
    }

    @Override
    public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
        //返回到浏览器
        res.getWriter().write("hello servlet");

    }

    @Override
    public String getServletInfo() {
        return null;
    }

    @Override
    public void destroy() {

    }
}

web.xml



         xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  


  
  servlet1
  class>com.rookie.bigdata.Servlet1class>


  
  
    servlet1
    /servlet1
  



  
    index.jsp
  

 

 2、整体流程图如下:

 3、针对上面代码的详细流程如下

1、启动tomact加载应用和web.xml文件

2、http访问程序 http://localhost:8080/servlet1,最终通过web.xml文件映射为com.rookie.bigdata.Servlet1

3、实例化Servlet1对象

4、调用Servlet1中的init方法

5、调用service方法接受浏览器请求

 

登录查看全部

参与评论

评论留言

还没有评论留言,赶紧来抢楼吧~~

手机查看

返回顶部

给这篇文章打个标签吧~

棒极了 糟糕透顶 好文章 PHP JAVA JS 小程序 Python SEO MySql 确认