Servlet基础-调用流程

一、Servlet调用流程图

1. 首先打开login.html,这个页面可以通过form以post的形式提交数据

2.在login.html将用户名、密码提交到"/login"的路径,并附带method为post

3.tomcat接受到一个新请求http://127.0.0.1:8080/login,到web.xml中进行匹配,发现/login对应的Servlet是LoginServlet。

4.tomcat定位到LoginServlet后,发现并没有LoginServlet实例存在,于是调用LoginServlet的public无参构造方法LoginServlet()实例化一个LoginServlet对象以备后续使用。

5.tomcat拿到LoginServlet实例后,根据页面上表单传过来的method="post",调用doPost方法。

6.doPost方法中,通过request.getParameter方法将传递过来的信息取出来。

7.将返回的内容设置到response中。到此Servlet的工作完成了。

8.tomcat拿到被Servlet修改过的response,根据response中的html字符串,通过HTTP协议将这个html字符串回传给浏览器。浏览器根据HTTP协议获取html字符串,渲染到界面上。

 

posted @ 2018-05-24 16:13  溯琮  阅读(236)  评论(0编辑  收藏  举报