01 package interval;
02
03 import javax.servlet.*;
04 import javax.servlet.http.*;
05 import java.io.*;
06 import java.util.Date;
07 import java.text.SimpleDateFormat;
08
09 public class TimeFilter implements Filter {
10 private FilterConfig filterConfig;
11 private String datetime_pattern;
12 private String comp;
13
14 public void init(FilterConfig filterConfig) {
15 this.filterConfig = filterConfig;
16 this.datetime_pattern = filterConfig.getInitParameter("datetime_pattern");
17 this.comp = filterConfig.getInitParameter("company");
18 }
19
20 public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) {
21 try {
22
23 SimpleDateFormat sdf = new SimpleDateFormat(datetime_pattern);
24 PrintWriter out = response.getWriter();
25 out.println(sdf.format(new Date()));
26
27 request.setAttribute("comp","<hr><em>"+ comp +"</em>");
28 filterChain.doFilter(request, response);
29 }
30 catch(ServletException sx) {
31 filterConfig.getServletContext().log(sx.getMessage());
32 }
33 catch(IOException iox) {
34 filterConfig.getServletContext().log(iox.getMessage());
35 }
36 }
37
38 public void destroy() {
39 }
40 }
|