【Java Web】把逻辑名映射到servlet文件

Ⅰ、请求URL

Ⅱ、容器搜索DD,查找servlet-mapping

<?xml version="1.0" encoding="ISO-8859-1" ?>

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
         version="2.4">

    <servlet>
        <servlet-name>Ch3 Beer</servlet-name>
        <servlet-class>com.example.web.BeerSelect</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>Ch3 Beer</servlet-name>
        <url-pattern>/SelectBeer.do</url-pattern>
    </servlet-mapping>

</web-app>

Ⅲ、找到url-pattrern所对应的DD内部的servlet-name

    <servlet-mapping>
        <servlet-name>Ch3 Beer</servlet-name>
        <url-pattern>/SelectBeer.do</url-pattern>
    </servlet-mapping>

Ⅳ、利用servlet-name查找对应的servlet

    <servlet>
        <servlet-name>Ch3 Beer</servlet-name>
        <servlet-class>com.example.web.BeerSelect</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>Ch3 Beer</servlet-name>
        <url-pattern>/SelectBeer.do</url-pattern>
    </servlet-mapping>

Ⅴ、容器加载类,并初始化servlet(如果还没有初始化的话)

    <servlet>
        <servlet-name>Ch3 Beer</servlet-name>
        <servlet-class>com.example.web.BeerSelect</servlet-class>
    </servlet>

Ⅵ、容器开启一个新线程处理并传递request(传递给servlet的service()方法)

 容器如何处理请求?

Ⅶ、容器把响应发回给客户

 

posted @ 2017-05-13 10:56  xkfx  阅读(521)  评论(0编辑  收藏  举报