Verification Code Flow
1, click the "Get SMS Verification" button, the mobile phone number will be non-"empty" judgment.
A) If blank, give a hint: Please enter the phone number.
b) If not empty, determine whether the mobile phone number conforms to the rules, does not meet the "mobile phone number does not meet the rules" prompt
c) If the phone number is not empty and conforms to the rules, take the second step
2. Eject the Verification Code input box.
A) page randomly generates 4 -digit verification code (including numbers and letters) and stores the phone number in a cookie
b) The user enters the verification code, and clicks the "OK" button, the verification code will be non-"null" and matching judgment
c) If the verification code is empty or does not match, the button does not react to it.
D) If it is not empty and the verification code matches, send the request (with the phone number parameter) to the background and request "Send SMS"
e) The user receives the SMS verification code. and enter the verification code, click to complete the registration. The background will be the phone number, verification code to judge. When the verification code does not match the phone number, a prompt will be given. When two matches, the registration succeeds.
JSP page
<%@ page language= "java" import= "java.util.*" pageencoding= "UTF-8"%><%string path = Request.getcontextpath () ; String basepath = request.getscheme () + "://" + request.getservername () + ":" + request.getserverport () + path + "/";%>&L t;! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" ><%@ page contenttype= "APPLICATION/JPG;CHARSET=GBK"%><%@ page import= "java.awt.*"%><%@ page import= "java.awt.image.*"%><jsp:directive.page import= "Javax.imageio.ImageIO"/ ><%bufferedimage img=new BufferedImage (60,26,BUFFEREDIMAGE.TYPE_USHORT_555_RGB); Graphics g=img.creategraphics (); G.setcolor (Color.decode ("#f0f0f0")); G.fillrect (0,0,60,26); String a=request.getparameter ("yy"), Session.setattribute ("yy", a), G.setfont (New Font ("Blackbody", font.bold,20)); G.setcolor (Color.decode ("#3a8cd5")); g.drawstring (a,5,20); for (int i=0;i<3;i++) {int j= (int) (Math.random () *256); int k= (int) (Math.random () *256), int l= (int) (Math.random () *256), int x1= (int) (Math.random () *61), int y1= (int) ( Math.random () *31); int x2= (int) (Math.random () *61); int y2= (int) (Math.random () *31); Color M=new color (j,k,l); G.setcolor (m); G.drawline (x1,y1,x2,y2);} Imageio.write (img, "JPG", Response.getoutputstream ()); Out.clear (); out = Pagecontext.pushbody ();%>
servlet Simple test code
Package Com.yanzheng;import Java.io.ioexception;import Javax.servlet.servletexception;import Javax.servlet.http.cookie;import Javax.servlet.http.httpservlet;import javax.servlet.http.HttpServletRequest; Import Javax.servlet.http.httpservletresponse;public class Sendphonecode extends HttpServlet {public void doget ( HttpServletRequest request, HttpServletResponse response) throws Servletexception, IOException {doPost (Request, Response);} public void DoPost (HttpServletRequest request, httpservletresponse response) throws Servletexception, IOException { String method = Request.getparameter ("method"), if (Method.equals ("Sendms")) {SENDMS (request, response);} if (Method.equals ("register")) {register (request, response);}} public void register (HttpServletRequest request, httpservletresponse response) throws Servletexception, IOException { Response.setcharacterencoding ("UTF-8"); String phonenum = Request.getparameter ("PhoneNumber"); cookie[] cookies = request.getcookies (); String testphonenum= ""; for (int i=0;i< cookies.length;i++) {if (Cookies[i].getname (). Equals ("PhoneNumber")) {System.out.println (Cookies[i].getvalue ()); Testphonenum=cookies[i].getvalue ();}} if (!phonenum.equals (Testphonenum)) {response.getwriter (). Write ("The phone number does not match the verification code!") ");} Else{response.getwriter (). Write ("Registered successfully! ");}} public void Sendms (HttpServletRequest request, httpservletresponse response) throws Servletexception, IOException { cookie[] cookies = request.getcookies (); String phonenum = Request.getparameter ("PhoneNumber"); String testphonenum= ""; for (int i=0;i<cookies.length;i++) {if (Cookies[i].getname () equals ("PhoneNumber")) { System.out.println (Cookies[i].getvalue ()); Testphonenum=cookies[i].getvalue ();}} System.out.println (Testphonenum.equals (Phonenum));}}
Mobile Verification Code Execution process