Session learning: prevents users from submitting forms repeatedly (single-State Design Mode-atomic design mode + MD5 Technology & amp; Base64 algorithm)

Source: Internet
Author: User

1. FormServlet. java designs a form to submit data to prevent users from repeatedly submitting data to the server. The blocking code is as follows:

FormServlet "text/html; charset = UTF-8" = "token", token ); "<form action = '/day07/servlet/DoFormServlet' method = 'post'>" "<input type = 'den den 'name = 'Token' value ='" + token + "'>" "User Name: <input type = 'text' name = 'username'> "" <input type = 'submit 'value = 'Submit'> "" </form> "TokenProccessor {TokenProccessor instance = string makeToken () {String token = (System. currentTimeMillis () + Random (). nextInt (999999999) + "" = MessageDigest. getInstance ("md5" md5 [] = BASE64Encoder encoder =

2. DoFormServlet. java implements the function of preventing repeated data submission on the client and server respectively. The Code is as follows:

DoFormServlet B = isToken (request); (B = "Please do not submit" "token" "again to process user submitted requests !! "= Request. getParameter (" token "(client_token =) {= (String) request. getSession (). getAttribute (" token "(server_token = ){(! Client_token.equals (server_token )){

 

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.