`

Servlet中Filter的使用

阅读更多
Filter作用 :
  每当使用应用服务器页面或servlet的时候,应用服务器就会根据web.xml里面配置的filter 去进行过滤处理。
   如:LINK项目中web.xml的filter配置
      <filter>
<filter-name>sessionRestoreFilter</filter-name>
<filter-class>com.liba.web.filter.SessionRestoreFilter</filter-class>
<init-param>
<param-name>loginURL</param-name>
<param-value>http://localhost:8080/login.jsp?cb=http://localhost:8080/permission</param-value>
</init-param>
<init-param>
<param-name>hibernateSessionFactoryName</param-name>
<param-value>java:/liba/hibernate/SessionFactory</param-value>
</init-param>
<init-param>
<param-name>userPermissionServiceName</param-name>
<param-value>liba/ejb/UserPermissionService/local</param-value>
</init-param>
</filter>

<filter-mapping>
<filter-name>sessionRestoreFilter</filter-name>
<url-pattern>*.action</url-pattern>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>

即每次执行.action的时候,都会去执行进行过滤处理。

调用处理过程就是:
1.接受request->去处理第一个filter.init-> 处理第一个filter.doFilter
2.如果不想继续使用filter过滤就在filter.doFilter中使用 return
  3.如果要继续使用filter过滤就在filter.doFilter中 使用chain.doFilter(servletRequest, servletResponse);
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics