To generate a "Login verification Code" method step

Source: Internet
Author: User

1. Add the Simplecaptcha rack package simple enough verification code production library. 2. New Captchamodule Module Class

public class captchamodule {         @At       @Ok ("Raw:png")         public bufferedimage next ( httpsession session,  @Param ("W")  int w, @Param ("H")  int h)  {             if  (w * h < 1)  {  //long or wide to 0? reset to default length width .            w =  200;            h = 60;         }        captcha captcha  = new captcha.builder (w, h)                                   .addtext ().Addbackground (New gradiatedbackgroundproducer ())                                   .gimp (New fisheyegimpyrenderer ())                                   .build ();         string  text = captcha.getanswer ();         Session.setattribute (toolkit.captcha_attr, text);         return  captcha.getimage ();     }}


    • Raw represents Rawview

    • PNG is the abbreviation for image/png in Rawview and is the description of data mime

    • The return value is BufferedImage, and this is image/png, so it turns into a picture display. Also support JPG/WEBP format, details refer to Rawview source bar.

    • CAPTCHA has more than n combination and configuration, the choice of their own

3. Add the Captcha text box to the page

<script type= "Text/javascript" >             function next_captcha ()  {                 $ ("#captcha_img"). attr ("src",  "${base}/captcha/next?_="  + new  date (). GetTime ());             }         </script>         Verification Code <input name= "Captcha"  type= "text"  value= "" >         </IMG> 

650) this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0003.gif "alt=" J_0003.gif "/>650" this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0005.gif "alt=" J_0005.gif "/>


This article from the "12403903" blog, reproduced please contact the author!

To generate a "Login verification Code" method step

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.