The main content of this article is: using Java image to make verification code .
Design ideas:
1. Copy Authimageservlet.class Image Verification code
2. Configure Web. xml
3, JSP, call the encapsulated Authimageservlet, realize the function of loading the verification code.
4. Remove the verification code stored in the session. Infer the correctness of the Verification Code in action
Compare your previous blog post Work Note 5. Java text box Verification code , the picture verification code adds security.
In action, the validation code in the session is taken out and the verification code entered is inferred.
Steps:
1 , copy authimageservlet.class image Verification Code
: HTTP://PAN.BAIDU.COM/S/1BNF7DCR
2. Configure Web. xml
<servlet><servlet-name>AuthImageServlet</servlet-name><servlet-class> cn.bjjczb.jyzgcx.util.authimageservlet</servlet-class></servlet><servlet-mapping>< servlet-name>authimageservlet</servlet-name><url-pattern>/servlet/authimageservlet</ Url-pattern></servlet-mapping>
3, JSP, call the encapsulated Authimageservlet. Implementation of the ability to load verification codes
<script type= "Text/javascript" >function ChangeCode () {var imgnode = document.getElementById ("vimg"); Again load the verification code, to achieve the purpose of the refresh imgnode.src = "${pagecontext.request.contextpath}/servlet/authimageservlet?t=" + math.random (); Problems preventing browser Caching}</script>
Verification code: <input type= "text" id= "Creditcodes" name= "creditcodes" class= "dz" style= "width:110px;" /><a href= "#" onclick= "ChangeCode ();" > Refresh </a>
4. Remove the verification code stored in the session and infer the correctness of the Verification Code in action
/** Login */public String login () throws Exception {//Get the captcha stored in session string Creditcode = (string) session.getattribute ("Ra nd ")///Darker input" Captcha creditcodes "matches Creditcode (ignore uppercase and lowercase) if (creditcodes.equalsignorecase (Creditcode)) {//Captcha input correct} else {//Verification code input Error}}
Used to get the user input verification code for the page, private string Creditcodes;public string Getcreditcodes () {return creditcodes;} public void Setcreditcodes (String creditcodes) {this.creditcodes = Creditcodes;}
Work Note 5. Java Picture Verification Code