Image Verification Code JSP

Source: Internet
Author: User

<%int width = 60;int height = 32;//create the imagebufferedimage image = new BufferedImage (width, height, bufferedimage . TYPE_INT_RGB); Graphics g = image.getgraphics ();//Set the background colorg.setcolor (new Color (0xDCDCDC)); G.fillrect (0, 0, width, heigh t);//Draw the Borderg.setcolor (Color.Black); g.drawrect (0, 0, width-1, height-1);//Create a random instance to genera Te the codesrandom rdm = new Random (); String hash1 = integer.tohexstring (Rdm.nextint ()); System.out.print (HASH1);//Make some confusionfor (int i = 0; i <; i++) {int x = rdm.nextint (width); int y = Int (height); g.drawoval (x, y, 0, 0);} Generate a random codestring capstr = hash1.substring (0, 4);//The generated verification code is stored in Sessionsession.setattribute ("Validatecode", CAPSTR); G.setcolor (new Color (0, 0)), G.setfont (New Font ("Candara", Font.Bold,)), g.DrawString (Capstr, 8, 24); G.dispose ();//Output Picture Response.setcontenttype ("Image/jpeg"); Out.clear (); out = Pagecontext.pushbody (); outputstream STRM = Response.getoutputstream(); Imageio.write (image, "JPEG", STRM); Strm.close ();%> 


Image Verification Code JSP

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