`
zgqynx
  • 浏览: 1364442 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

避免重复提交  资源 struts

阅读更多
[size=18]原文:http://www.kpwang.com/pc/view_e.jsp?board_id=1&article_id=1106127144019
the other resource is more better
http://www.learntechnology.net/content/struts/struts_token.jsp
Use Struts Token mechanism submitted to repeat Form

Struts Token (Token) Form mechanism can be used to solve the problem of duplication. basic tenets are : the server in handling the request arrived, Token request will be included in the value and preservation of the current user session token value, to see whether they match. Handle the request, and in reply sent to the client, will have a new token. Apart from the token pass Client, users will be preserved conversation replace the old token. If such users have retreated back to the author's page and again, Chuan up on the client and server side of the Token Token inconsistent, so as to effectively prevent the occurrence of multiple submissions. . Kunpeng Network
. Kunpeng Network

In fact,
time is two points : Firstly, you need to have the token value in the request, the request of token value preservation. In fact, on the page and we usually retain some of the same information through the hidden field to the depositary, in the form such as :"input type="hidden"name="org.apache.struts.taglib.html.TOKEN"value="6aa35341f25184fd996c4c918255c3ae"> TokenProcessor category is the value of generateToken () agreed. According to current users and is the current session id long time to calculate the value. Client : In the second submission, we should judge whether the value of the request and the server contains the same token, submitted for each server will generate new Token, so if it is submitted to repeat. Client Server and the value of the Token Token value will be inconsistent. Now, to be inserted in the database data to illustrate how to prevent a repeat submitted.

Action in the add methods, we need to preserve the page Token value of a specific demand. increased only one sentence : saveToken (request); ,
as follows :
Public ActionForward add (ActionMapping mapping. ActionForm form.
HttpServletRequest request. HttpServletResponse response)
4003rd omitted from the front to deal with the
saveToken (request);
Return mapping.findForward ("add");
Action in the insert method), According to the Form Token Token value and the value of the server, as follows :
Public ActionForward insert (ActionMapping mapping. ActionForm form.
HttpServletRequest request. HttpServletResponse response)
If (isTokenValid (request, true)) (
4003rd submit Form not repeat the
// here is the preservation of data codes"
} else --
4003rd submit Form repeat
saveToken (request);
4003rd other processing code
}
}


222222222222222222222222222222222222222222222222222222222222222222222

1. Duplicate submission, duplicate set the scene
duplicate submission, duplicate set of records are to solve the problem of redundant systems. In other words, a person to submit a certain number of records (Why? Perhaps it is no idle matter of the stem; Most likely it will be submitted to the users simply do not know whether the results had been carried out?).

However, there is a need to address the problem and not depend on your development system category. For example, you took over is a resource management system, the system itself from the point of view of demand, it does not allow a"repeat"of the record in such demand constraints, The move will trigger a repeat submitted to the implementation of the"Business Class"production it is simply impossible to implement successfully avoid indifferent to avoid the problem.

2. Retreat from the scene to prevent"a repeat
understanding set to repeat the scene. Let's take a look"to prevent the retreat of"operational reasons what is it? For instance, one in the development of a voting system, it has many steps, and there was a link between these steps. For example, certain information will be sent first to second, second cache of such information, also sent its own message to the third stage. . . . . And so on, users at the third step at this time, we imagine a naughty user hits the back button users. For the second time screen steps pages, he amended or re-submission access to the next step (which is the third step), the error will have in this? ! What mistakes? This is the most typical example of the operation of information directly led to the loss for the first step! (If this information is then stored on Request. Of course, you can be stored in the greater context or environment Session, But this is not a good idea! Information stored on the issue until a detailed discussion on this issue)


3. The problem of how to handle the
course, many of the systems (such as booking system is to allow individuals to repeat the demand for reservations) must be updated to avoid duplication. duplicate submission, and to prevent back problems, but even that is the problem, have to deal with the distinction between how and where (the Internet tells you how to handle But rarely distinguish where treatment), obviously dealing with the client or server is nothing more than two. and the different ways to handle the position is different, but one thing to declare : Any client (especially B/S end) are dealing with can not be trusted. is the best and most server should handle the matter.

Client processing :
Client Script we can use Javascript to face to resolve, as

1. Set to repeat, repeat submitted
Ways One : the establishment of a variable, allowing only one submission.
<script language="javascript">
Var = false; checkSubmit***
CheckSubmit function () (
If (checkSubmit*** ====== true) (
Return false;
      }
CheckSubmit*** = true;
Return true;
   }
Docondblclick document.ondblclick = function () (
Window.event.returnValue = false;
   }
Doconclick document.onclick = function () (
If (checkSubmit***) (
Window.event.returnValue = false;
       }
   }
</script>
<html:form action="myAction.do"method="post"onsubmit="return checkSubmit();">

Way Two : to be submitted to the Home button to disable or image
<html:form action="myAction.do"method="post"
Onsubmit="getElById ( 'submitInput'). Disabled = true; return true;">
<html:image styleId="submitInput"src="images/ok_b.gif"border="0"/>
</html:form>


2. Prevent users retreat
here is wonderful, some of the historical record of changes to the browser. For example, the use of window.history.forward (); Some of the"new page with the URL to replace the current historical records, the historical record on this visit is only one page. buttons will never retreat into useable."For example, the use of Javascript : location.replace (this.href); event.returnValue=false;


2. Server processing (Here I will only deal with the Struts Framework)
Using synchrotron Token (Token) mechanism to solve the problem of Web application repeat, Struts also gives a reference implementation.

Basic tenets :
Before arriving in the server request. Token request will be included in the value and preservation of the current user session token value,
See whether or not matching. Handle the request, and in reply sent to the client, will have a new token. Apart from the token pass
Client, users will be preserved conversation replace the old token. If such users have retreated to the back pages and re-submit
tabled, Chuan up on the client and server side of the Token Token inconsistent, so as to effectively prevent the occurrence of multiple submissions.

If (isTokenValid (request, true)) (
4003rd your code here
Return mapping.findForward ("success");
) Else (
SaveToken (request);
Return mapping.findForward ("submitagain");
}

Conversation ID Struts users and the current system time to generate a unique (for each conversation) Token. achieve specific reference"to the category
TokenProcessor generateToken () method.

1. 4003rd Token Verification Service control,"html : form"logo will be automatically generated based on an implicit input session which represents token, twice to prevent the
2. In action :


// //<input type="hidden"name="org.apache.struts.taglib.html.TOKEN"
4003rd value="6aa35341f25184fd996c4c918255c3ae""
If (!isTokenValid (request))
Errors.add (ActionErrors.GLOBAL_ERROR,
New ActionError ("error.transaction.token"));
ResetToken (request); 4003rd delete the token session

3. This action is a method for generating token
protected String generateToken (HttpServletRequest request) (
HttpSession session = request.getSession ();
Try (
Id[] session.getId byte = (). GetBytes ();
= Byte now[]
New Long (System.currentTimeMillis ()). ToString (). GetBytes ();
MessageDigest md = MessageDigest.getInstance ("MD5");
Md.update (id);
Md.update (now);
Return (toHex (md.digest ()));
) Catch (IllegalStateException e) (
Return (null);
) Catch (NoSuchAlgorithmException e) (
Return (null);
       }
   }

Aggregate
submitted for repeat, repeat set. prevent regression, etc. are all systems need to be addressed in order to avoid duplication of records. deal with the needs of each client may propose appropriate solutions. But it is only in the server for testing the authenticity of the data. Token-based processing is the method once and for all.

Meanwhile, we also see that to look at problems from a different perspective, the solution is different. Client users more pursuit of the operation and services will focus on the data processing end. Therefore, in a seemingly easy question for the server, client used to solve a lot of trouble! Instead still. Therefore, we need to deal with certain issues in a comprehensive consideration and balance, which is used to solve client? Or a server to handle
Use Struts Token mechanism submitted to repeat Form [/size][b]
分享到:
评论

相关推荐

    Struts2防止重复提交解决方案

    在Struts2中,防止重复提交是一个重要的问题,因为它可能导致数据不一致性和服务器资源的浪费。本文将详细介绍如何在Struts2中解决这个问题,以及相关的技术概念。 首先,我们要理解Struts2中的拦截器(Interceptor...

    通过xml配置搞定Struts重复提交问题

    然而,Struts框架在处理HTTP请求时,如果没有适当的防护措施,可能会遇到重复提交的问题,这可能导致数据不一致或者服务器资源的浪费。在本文中,我们将深入探讨如何通过XML配置来解决Struts中的重复提交问题。 ...

    Servlet、Struts、SpringMVC对于表单重复提交的解决方案

    在Servlet中,通常采用几种方法来避免重复提交: 1. **Session状态管理**:在接收到用户提交请求后,可以在Session中设置一个标志,如"formSubmitted",然后在后续的请求中检查这个标志,如果已存在则忽略请求。 2...

    Struts2自定义拦截器实现防止重复提交

    总结来说,防止重复提交的自定义拦截器在Struts2中起到了关键作用,通过生成和验证令牌,能够在不依赖Struts2标签的情况下,有效地避免了用户意外或恶意的重复提交,保证了应用的稳定性和数据的一致性。

    Struts2防止重复提交的解决方案

    - 使用JavaScript禁用提交按钮或者通过AJAX异步提交表单,从而避免用户误操作导致的重复提交。 #### 四、Struts2相关开发技巧 除了防止重复提交外,Struts2还提供了丰富的功能支持,包括但不限于: 1. **处理结果...

    不能重复提交

    这种情况下,如果没有采取适当的措施来防止重复提交,可能会引起数据冗余、资源浪费甚至业务逻辑错误等问题。因此,在实际项目开发中,防止重复提交是一项非常重要的工作。 #### 防止重复提交的方法 1. **前端控制*...

    struts2中防止重复提交的方法

    在Struts2框架中,防止重复提交是一个重要的安全性考量,因为重复提交可能导致数据不一致性和资源浪费。在上述描述中,给出了三种主要方法来解决这个问题: 1) **使用 `&lt;s:token&gt;` 标签** Struts2 提供了一个称为 ...

    struts1.2之token解决重复提交

    Struts1.2框架在处理Web应用时,尤其是在表单提交场景中,可能会遇到重复提交的问题。这会导致数据不一致性和服务器资源的浪费。为了解决这个问题,Struts1.2引入了Token机制,用于防止用户意外或恶意的多次点击提交...

    JSP避免Form重复提交的三种方案

    在Web开发中,尤其是使用JavaServer Pages (JSP)时,Form表单的重复提交问题是一个常见的挑战。这可能导致数据不一致性和服务器资源的浪费。本文将探讨三种防止JSP表单重复提交的方法。 首先,我们可以使用...

    防止表单重复提交

    然而,如果没有适当处理,可能会出现表单重复提交的问题,这可能导致数据的不一致性和服务器资源的浪费。本篇文章将深入探讨如何防止表单重复提交,主要关注于基于Struts2框架的解决方案。 首先,理解表单重复提交...

    JSP_重复提交_解决方法

    例如,在某些资源管理系统中,系统设计本身就禁止重复的数据记录,因此即便用户尝试重复提交,也不会造成实质性的后果。 ##### 2.2 防止后退操作 **场景说明**:在多步骤表单填写或操作流程中,如果用户在完成某个...

    重复提交问题例子

    在IT行业中,尤其是在Web开发领域,"重复提交问题"是一个常见的问题,它可能导致数据的不一致性和服务器资源的浪费。本示例将介绍如何利用Struts框架中的Token机制来解决这个问题。 Struts是一个广泛使用的MVC...

    Java怎样防止重复提交

    在Java Web开发中,防止重复提交是一个重要的议题,尤其是在大型分布式应用中,因为这可能导致服务器资源的过度消耗,甚至引发系统性能问题。以下是一些防止重复提交的常见策略和技术: 1. **令牌(Token)机制**:...

    Struts1.3 备忘笔记

    09 Struts_09Token : Structs的令牌机制,避免重复提交问题 10 Struts_10SmartUpload : structs的文件上传 11 Struts_11Internationalize : Structs的国际化和消息文件的使用 12 Struts_12GeneralApply : Structs的...

    struts2课程笔记

    防止表单重复提交是Web开发中的常见问题,Struts2通过令牌机制来解决这个问题,避免了同一操作被多次执行。 项目练习部分涉及到使用Ajax实现异步请求并返回JSON数据,这通常通过Struts2的JSON插件实现。文件下载则...

    struts示例

    这两种方式在处理用户导航和防止重复提交方面有所不同。 7. **国际化和本地化**:Struts框架支持多语言,可以在应用中添加资源文件(如message.properties或message_zh_CN.properties),以便根据用户的浏览器设置...

Global site tag (gtag.js) - Google Analytics