web.xml分发器:
case1: springMvc的分发器:
作用:将匹配上的请求交由springMvc处理,路径会继续到达springMvc的处理器映射器
<servlet> <servlet-name>springmvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring/*-servlet.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springmvc</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping>
case2: 自定义servlet分发器:
作用:在自己的servlet中可以自由处理,web.xml的url优先匹配已定义的pattern,最后匹配<url-pattern>/</url-pattern>
<servlet> <servlet-name>Func1</servlet-name> <servlet-class>com.softroad.fun1.action.Func1_Servlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>Func1</servlet-name> <url-pattern>/Func1/*</url-pattern> </servlet-mapping>
web.xml过滤器:
自定义过滤器:拦截请求、验证权限、文件加密或者解密
<filter> <filter-name>Filter1</filter-name> <filter-class>com.softroad.filter.Login_Filter</filter-class> </filter> <filter-mapping> <filter-name>Filter1</filter-name> <url-pattern>/Func2/*</url-pattern> </filter-mapping>