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

📄 timetrackfilter.java

📁 USB设计的一些源码!适合与USB开发的同学!还是蛮不错的!我用过一些!
💻 JAVA
字号:
import javax.servlet.*;
import java.util.*;
import java.io.*;

public class TimeTrackFilter implements Filter {
     private FilterConfig filterConfig = null;

     public void init(FilterConfig filterConfig)
        throws ServletException {

        this.filterConfig = filterConfig;
     }

     public void destroy() {

        this.filterConfig = null;
     }

     public void doFilter( ServletRequest request,
        ServletResponse response, FilterChain chain )
        throws IOException, ServletException {

        Date startTime, endTime;
        double totalTime;

        startTime = new Date();

        // Forward the request to the next resource in the chain
        chain.doFilter(request, response);

        // -- Process the response -- \\

        // Calculate the difference between the start time and end time
        endTime = new Date();
        totalTime = endTime.getTime() - startTime.getTime();
        totalTime = totalTime / 1000; //Convert from milliseconds to seconds

        StringWriter sw = new StringWriter();
        PrintWriter writer = new PrintWriter(sw);

        writer.println();
        writer.println("===============");
        writer.println("Total elapsed time is: " + totalTime + " seconds." );
        writer.println("===============");

        // Log the resulting string
        writer.flush();
        //filterConfig.getServletContext().log(sw.getBuffer().toString());
         System.out.println(sw.getBuffer().toString());  

     }
}

⌨️ 快捷键说明

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