首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

filter范例

2012-12-27 
filter实例web.xml:????filterfilter-nameFilterTest/filter-namefilter-classorg.util.filterTes

filter实例

web.xml:

?

???

                 <filter>    <filter-name>FilterTest</filter-name>    <filter-class>org.util.filterTest</filter-class></filter>                <filter-mapping>     <filter-name>FilterTest</filter-name>      <url-pattern>/h1.jsp</url-pattern>  //指定过滤器过滤的页面,如果写“/”则是所有请求</filter-mapping>

?

filterTest.java:

public class filterTest implements Filter{public void destroy() {// TODO Auto-generated method stub}public void doFilter(ServletRequest arg0, ServletResponse arg1,FilterChain arg2) throws IOException, ServletException {// TODO Auto-generated method stubSystem.out.println("filter start");    }public void init(FilterConfig arg0) throws ServletException {// TODO Auto-generated method stub}}

?

?

在游览器中输入http://localhost:8080/Test/h1.jsp则会打印filter start

输入http://localhost:8080/Test/h2.jsp则不会打印

热点排行