开发者

Web.xml - url pattern mapped twice

开发者 https://www.devze.com 2023-01-07 11:07 出处:网络
A web.xml of ours contains following excerpt.. <servlet> <servlet-name>testServlet</servlet-name>

A web.xml of ours contains following excerpt..

<servlet>
    <servlet-name>testServlet</servlet-name>
    <servlet-class>
        org.springframework.web.servlet.DispatcherServlet
    </servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>testServlet</servlet-name>
    <url-pattern>*.htm</url-pattern>
</servlet-mapping>

<filter>
    <filter-name>anotherServlet</filter-name>
    <filter-class>com.test.anotherServlet</filter-class>    
</filter>
<filter-mapping>
    <filter-name>anotherServlet</filter-name>
    <url-pattern>*.htm</url-pattern>
</filter-mapping>

I need to unders开发者_StackOverflow社区tand as to how the container maps when an *.htm (say hello.htm ) url is encountered ..what happens when such a request happens.


The second mapping is for a filter, not a servlet.

When a request comes in the servlet container, it is first passed through a chain of any filters, then to the servlet, then back out through the filters in reverse order.

Filters have a slightly different API from servlets: There's a method called doFilter() that gets a ServletRequest and a ServletResponse. It calls the rest of the chain via chain.doFilter with the same parameters; at the end of the filter chain, those parameters are passed to the servlet. So filters are able to change or even substitute the request object coming in, and the response object coming out.

There's a little more info here.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号