分类: Java
2014-03-13 16:26:49
1. package samples;
2.
3. public class TimeBasedAccessInterceptor extends HandlerInterceptorAdapter {
4.
5. private int openingTime;
6. private int closingTime;
7.
8. public void setOpeningTime(int openingTime) {
9. this.openingTime = openingTime;
10. }
11.
12. public void setClosingTime(int closingTime) {
13. this.closingTime = closingTime;
14. }
15.
16. public boolean preHandle(
17. HttpServletRequest request,
18. HttpServletResponse response,
19. Object handler) throws Exception {
20.
21. Calendar cal = Calendar.getInstance();
22. int hour = cal.get(HOUR_OF_DAY);
23. if (openingTime <= hour && hour < closingTime) {
24. return true;
25. } else {
26. response.sendRedirect("");
27. return false;
28. }
29. }
30. }
配置xml bean: