67,515
社区成员
发帖
与我相关
我的任务
分享
public void init(FilterConfig filterConfig) throws ServletException {
}
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpSession session = ((HttpServletRequest) request).getSession();
State state = (State) session.getAttribute("State");
long currentTime = System.currentTimeMillis();
if (state == null) {
state = new State();
state.endTime = currentTime + 间隔时间;
session.setAttribute("State", state);
}
if (currentTime <= state.endTime) {
state.time++;
} else {
state.endTime += 间隔时间;
state.time = 1;
}
if (state.time <= 允许登录次数) {
chain.doFilter(request, response);
}
}
public void destroy() {
}
private static final long 间隔时间 = 1000 * 60;
private static final int 允许登录次数 = 10;
private class State {
private long endTime;
private int time;
}