<%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 = Rdm.next 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