Recording
<%@ page contenttype= "image/jpeg" import= "java.awt.*,java.awt.image.*,java.util.*,javax.imageio.*"%><%! Color getrandcolor (int fc, int BC) {Random rd = new random (), if (FC > 255) FC = 255;if (BC > 255) BC = 255;int r = Rd. Nextint (BC-FC); int g = Rd.nextint (BC-FC); int b = Rd.nextint (BC-FC); return new Color (R,G,B);} %><%response.setheader ("Pragma", "No-cache"), Response.setheader ("Cache-control", "No-cache"); Response.setdateheader ("Expires", 0); int width =, height = 20; BufferedImage image = new BufferedImage (WIDTH,HEIGHT,BUFFEREDIMAGE.TYPE_INT_RGB); Graphics g = image.getgraphics (); Random rd = new random (), G.setcolor (Getrandcolor (200,250)), G.fillrect (0, 0, width, height), G.setfont (New Font ("Times New Roman ", font.plain,18)); G.setcolor (new Color (255,255,255)); G.drawrect (0, 0, width-1, height-1); G.setcolor ( Getrandcolor (160,200)); for (int i=0;i<155;i++) {int x = rd.nextint (width); int y = rd.nextint (height); int xl = Rd.nextint (12); int yl = Rd. Nextint (12); G.drawline (x,y,x+xl,y+yl);} String srand= ""; for (int i=0;i<4;i++) {String rand=string.valueof (Rd.nextint (10)); Srand+=rand; G.setcolor (New Color (20+rd.nextint, 20+rd.nextint), 20+rd.nextint (110)); g.DrawString (rand,13*i+6,16); } session.setattribute ("Rand", SRand); G.dispose (); Imageio.write (image, "JPEG", Response.getoutputstream ()); Out.clear (); out = Pagecontext.pushbody ();% >
Called as a picture by another page
.
JSP Generate verification Code