web.xml中同一servlet/filter配置多个url-pattern

转自:http://blog.sina.com.cn/s/blog_4c2c2a0c0100dh67.html

 

若你的servlet要多个地址,或你的filter需要过滤不同的url如有*.jsp,*.do等,有好几个怎么做呢

 

其实很简单,以下的filter就是一个例子,encodingFilter配置了过滤了两个url-pattern

    <filter>

       <filter-name>encodingFilter</filter-name>

       <filter-class>com.cs.cms.filter.EncodingFilter</filter-class>

       <init-param>

           <param-name>encoding</param-name>

           <param-value>gbk</param-value>

       </init-param>

    </filter>

    <filter-mapping>

       <filter-name>encodingFilter</filter-name>

       <url-pattern>*.html</url-pattern>

    </filter-mapping>

    <filter-mapping>

       <filter-name>encodingFilter</filter-name>

       <url-pattern>*.jsp</url-pattern>

    </filter-mapping>

posted @ 2013-08-30 23:19  明明是悟空  阅读(1031)  评论(0编辑  收藏  举报