标签:形参 ons for 具体类 data- web std time url
public class TimeFilter implements Filter {
private int start = 0;
private int end = 24;
public void init(FilterConfig filterConfig) throws ServletException {
System.out.println("TimeFilter初始化,开始抓取初始化参数");
start = Integer.parseInt(filterConfig.getInitParameter("start"));
end = Integer.parseInt(filterConfig.getInitParameter("end"));
}
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
System.out.println("TimeFilter过滤");
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
int curHour = calendar.get(Calendar.HOUR_OF_DAY);
if (curHour >= end || curHour < start) {
request.setAttribute("start", start);
request.setAttribute("end", end);
request.getRequestDispatcher("/WEB-INF/notice.jsp").forward(request, response);
}
chain.doFilter(request, response);
}
public void destroy() {
System.out.println("TimeFilter爆炸");
}
}
<filter>
<filter-name>timeFilter</filter-name>
<filter-class>com.zker.TimeFilter</filter-class>
<init-param>
<param-name>start</param-name>
<param-value>15</param-value>
</init-param>
<init-param>
<param-name>end</param-name>
<param-value>22</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>timeFilter</filter-name>
<url-pattern>/limit/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>timeFilter</filter-name>
<url-pattern>/limit/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
标签:形参 ons for 具体类 data- web std time url
原文地址:http://www.cnblogs.com/deng-cc/p/7462923.html