⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 genericfilter.java

📁 icsamples目录中有icsamples网络程序。 这个程序包括J2EE网络层的范例程序
💻 JAVA
字号:
package jwadbook.filter;import javax.servlet.ServletRequest;import javax.servlet.ServletResponse;import javax.servlet.Filter;import javax.servlet.FilterChain;import javax.servlet.FilterConfig;import java.io.FileOutputStream;/** * * @author Jian (James) Cai */public class GenericFilter implements javax.servlet.Filter {	 private boolean logToFile = true;	 private String logFileName = "../logs/filtertest.out";	 private FileOutputStream logFileOut=null;    /** Creates new GenericFilter */    private FilterConfig filterConfig;        public GenericFilter () {    }    public void doFilter(final ServletRequest request,final ServletResponse response,FilterChain chain) throws java.io.IOException, javax.servlet.ServletException     {      chain.doFilter(request, response);    }        public void init(final FilterConfig filterConfig)     {      this.filterConfig=filterConfig;    }    public void destroy()    {    }    /***********************************************************     * Log a message to the servlet context application log.     *     * @param message Message to be logged     **********************************************************/    protected void log(String message) {	try	    {		if ( logToFile==true )		    {			if ( logFileOut == null )			    {				logFileOut = new FileOutputStream( logFileName, true );			    }			  			logFileOut.write( ("Filter Test: " + message).getBytes());			logFileOut.write ( "\n".getBytes());		    }		System.out.println("Filter Test: " + message);	    }		catch (Exception e )		{			System.out.println("Exception occured : " + e );		}    }    /*******************************************************************     * Log a message and associated exception to the servlet context     * application log.     *     * @param message Message to be logged     * @param throwable Exception to be logged     ******************************************************************/    protected void log(String message, Throwable throwable) {			try	    {		if ( logToFile==true )		    {			if ( logFileOut == null )			      {				  logFileOut = new FileOutputStream( logFileName );			      }			  			logFileOut.write( ("Filter Test: " + message).getBytes() );			logFileOut.write ( "\n".getBytes() );		    }		System.out.println("Filter Test: system out !!!! " + message);		throwable.printStackTrace(System.out);	    }	catch (Exception e )	    {		System.out.println("Exception occured : " + e );	    }    }    } //end of GenericFilter

⌨️ 快捷键说明

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