(reproduced) session token mechanism

Source: Internet
Author: User

Http://blog.chinaunix.net/uid-26642709-id-3061264.html

When using the session token, you must use the STRUTS2 Table tag library, you cannot use HTML to prevent duplicate submissions via session token: When the client requests the page, the server generates a random number from the token tag and places the random number in the session. The random number is then sent to the client, and if the client submits it for the first time, then the browser sends the random number to the server and the server receives the random number and compares it to the random number saved in the session, when the value is the same, and the server considers it the first commit. And will update the server side of this random value, if this time again, the client to the server side of the random number is the previous one, and the server side of the random number has changed, the two different, the server think this thing repeated commit, And then turn to the results page that Invalid.token points to. token.jsp<%@ page language= "java" import= "java.util.*" pageencoding= "Iso-8859-1"%>
<% @taglib prefix = "s" uri= "/struts-tags"%>
<body>
<s:form action = "token.action" theme = "Simple" >
Username: <s:textfield name = "username" ></s:textfield><br>
Password:<s:password name = "Password" ></s:password><br>

<s:token></s:token>
<s:submit value = "Submit" ></s:submit>

</s:form> </body>
<action name = "token" class = "com.shengsiyuan.struts2.TokenAction" >
<result name = "Success" >/tokenSuccess.jsp</result>
<result name = "Invalid.token" >tokenFail.jsp</result> <!--times is a special case of input.
<interceptor-ref name = "token" ></interceptor-ref>
<interceptor-ref name= "Defaultstack" ></interceptor-ref>
</action>
Tokenaction.javapackage Com.shengsiyuan.struts2;import Com.opensymphony.xwork2.actionsupport;public Class Tokenaction extends Actionsupport
{
Private String username;
private String password;
Public String GetUserName () {
return username;
}
public void Setusername (String username) {
This.username = Username;
}
Public String GetPassword () {
return password;
}
public void SetPassword (String password) {
This.password = password;
}
@Override
Public String Execute () throws Exception {
return SUCCESS;
}
}tokensuccess.jsp<%@ page language= "java" import= "java.util.*" pageencoding= "Iso-8859-1"%>
<% @taglib prefix = "s" uri = "/struts-tags"%>
<body>
Username:<s:property value = "username"/><br>
Password:<s:property value = "Password"/>

</body>
<body>
Do not submit the form repeatedly
</body>

(reproduced) session token mechanism

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.