防止表单重复提交(注入的方式)

1.jsp页面中

<%@ taglib prefix="s" uri="/struts-tags"%>

表单中加上<s:token></s:token>

 

2.在action中

@Results({
        @Result(name = "invalid.token", location ="url"),
})

@InterceptorRefs( {
    @InterceptorRef(value = "token",params={"includeMethods","actionmethod"}),  //actionmethod:方法名
    @InterceptorRef(value = "defaultStack")
})

 

原理:在提交表单时,随机生成session令牌存在session中,当表单重复提交时,生成新的令牌和存着的令牌匹配,如果匹配不一样,则禁止跳action。

posted @ 2015-10-14 21:06  陈茜茜  阅读(271)  评论(0)    收藏  举报