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 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

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.