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 verification code,
4, remove the verification code stored in the session, in action to determine the correctness of the Verification code
Compare Previous blog posts Work Note 5. Java text box Verification Code , the image verification code adds security.
In action, the verification code in the session is taken out to determine whether the verification code entered is matched.
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, realize the function of loading verification code
<script type= "Text/javascript" >function ChangeCode () {var imgnode = document.getElementById ("vimg"); Reload 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, in action to determine the correctness of the Verification code
/** Login */public String login () throws Exception {//Get the captcha stored in session string Creditcode = (string) session.getattribute ("Ra nd ") (//) if the" Captcha Creditcodes "entered is matched with the creditcode (ignoring case) if (Creditcodes.equalsignorecase (Creditcode)) {//Verify code entered correctly} 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