Work Note 5. Java Picture Verification Code

Source: Internet
Author: User

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

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.