testfilter.java

来自「一个很好的Java函数实例」· Java 代码 · 共 41 行

JAVA
41
字号
package apibook.c7.s1;import javax.servlet.*;import java.io.IOException;import javax.servlet.http.*;//测试Filter接口public class TestFilter implements Filter {  FilterConfig config;  public TestFilter() {  }  public void setFilterConfig(FilterConfig config) {    this.config = config;  }  public FilterConfig getFilterConfig() {    return config;  }  public static void main(String[] args) {    TestFilter testFilter1 = new TestFilter();  }  public void init(FilterConfig parm1) throws javax.servlet.ServletException {    /**@todo Implement this javax.servlet.Filter method*/    throw new java.lang.UnsupportedOperationException("Method init() not yet implemented.");  }  public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws java.io.IOException, javax.servlet.ServletException {    ServletContext context = getFilterConfig().getServletContext();    long bef = System.currentTimeMillis();    chain.doFilter(req, res); // no chain parameter needed here    long aft = System.currentTimeMillis();    context.log("Request to " + req.getServerName() + ": " + (aft-bef));//.getRequestURI()  }  public void destroy() {    /**@todo Implement this javax.servlet.Filter method*/    throw new java.lang.UnsupportedOperationException("Method destroy() not yet implemented.");  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?