防止重复提交
来源:互联网 发布:java 内存泄露检测 编辑:程序博客网 时间:2024/05/29 16:30
/** * Token * Created by Administrator on 2017/4/27. * 防止重复提交注解,用于方法上 * 在新建页面方法上,设置needSaveToken()为true,此时拦截器会在Session中保存一个token, * * *********************************************** * 同时需要在新建的页面中添加 * <input type="hidden" name="token" value="${token}"> * 保存方法需要验证重复提交的,设置needRemoveToken为true * *********************************************** * * 此时会在拦截器中验证是否重复提交 */@Target(ElementType.METHOD)@Retention(RetentionPolicy.RUNTIME)public @interface Token { boolean needSaveToken() default false; boolean needRemoveToken() default false;}添加拦截器
package com.nroad.interceptor;
import com.nroad.dto.AuthToken;
import com.nroad.service.UserService;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
/**
* AuthInterceptor
* Created by Administrator on 2017/4/21.
* 身份验证拦截器
*/
public class AuthInterceptor extends HandlerInterceptorAdapter {
@Overridepublic boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException { HttpSession session = request.getSession();
// if (handler instanceof HandlerMethod) {
// HandlerMethod handlerMethod = (HandlerMethod) handler;
//获取身份令牌
AuthToken at = (AuthToken) session.getAttribute(AuthToken.SESSION_NAME);
//检查身份令牌
if (null == at || null == at.getUser()) {
//登陆验证未通过 ,返回到登陆界面
response.sendRedirect(“/”);
return false;
}
//检查session
HttpSession httpSession = UserService.USER_SESSION.get(at.getUser().getUsername());
if (!httpSession.getId().equals(session.getId())){
//账号已异地登陆
session.invalidate();
response.sendRedirect(“/?loginExce01”);
return false;
}
//登陆验证通过.流程继续
return true;
// }
// return true;
}
}
“`
- 防止重复提交数据
- 防止重复提交
- struts防止重复提交
- 防止表单重复提交
- 防止重复提交
- 防止重复提交表单
- javascript 防止重复提交
- Struts防止重复提交
- 防止struts重复提交
- 防止重复提交
- javascript 防止重复提交
- Struts2 防止重复提交
- 防止重复提交
- 防止servlet重复提交
- 防止重复提交
- Webwork防止重复提交
- 防止button重复提交
- 防止form 重复提交
- QT QML初体验随笔之QQuickView(7)
- 如何破解myeclipse经典版本8.5,8.6
- slf4j-api、slf4j-log4j12以及log4j之间什么关系?
- 电子表格控件Aspose.Cells V17.5全新发布 | 附下载
- bootstrap
- 防止重复提交
- PHP两个数组相加如何合并?
- eclipse c++ 加 MinGW GCC 生成Dll,以及调用Dll方法详解
- JQ 滚动到页面底部事件的判断
- 在VMWare下安装Linux(CentOS)
- controller接收前台数据—中文乱码问题
- C++向上转换
- oracle查询sql执行时间
- (三)Linux下Hadoop2以上版本安装配置