Click "cannot see or change one"
Test cases:
Index. jsp
<% @ Page contenttype = "text/html; charset = UTF-8" Language = "Java" Import = "Java. util. * "errorpage =" "%> <HTML> Package assumervlet; import Java. AWT. color; import Java. AWT. font; import Java. AWT. graphics; import Java. AWT. image. bufferedimage; import Java. io. ioexception; import Java. util. random; import javax. imageIO. imageIO; import javax. servlet. servletexception; import javax. servlet. HTTP. httpservlet; import javax. servlet. HTTP. httpservletrequest; import javax. servlet. HTTP. httpservletresponse; public class imagemaskservlet Extends httpservlet {public void doget (httpservletrequest request, response) throws servletexception, ioexception {dopost (request, response);} public void dopost (httpservletrequest request, response) throws servletexception, ioexception {response. setheader ("Pragma", "No-Cache"); response. setheader ("cache-control", "No-Cache"); response. setdateheader ("expires", 0); Int width = 60, Height = 20; // create an image bufferedimage image = new bufferedimage (width, height, bufferedimage. type_int_rgb); // obtain the graphic context graphics = image. getgraphics (); // generate random class random = new random (); // set the background color graphics. setcolor (getrandcolor (200,250); // the size of the Verification Code graphics. fillrect (0, 0, width, height); // set the font graphics. setfont (new font ("Times New Roman", Font. plain, 18); // graphics. setcolor (getrandcolo R (160,200); // generates 155 random interference lines, making it difficult for other programs to detect the for (INT I = 0; I <155; I ++) in the image) {int x = random. nextint (width); int y = random. nextint (height); int XL = random. nextint (12); int yl = random. nextint (12); graphics. drawline (X, Y, x + XL, Y + yl);} // obtain the random ID code (4 digits) string srand = ""; for (INT I = 0; I <4; I ++) {// 0 ~ 9 string Rand = string. valueof (random. nextint (10); srand + = rand; // sets the digital color graphics. setcolor (new color (20 + random. nextint (110), 20 + random. nextint (110), 20 + random. nextint (110); // draw a random 4-Digit Image in graphics. drawstring (RAND, 13 * I + 6, 16);} // put the request in the session. getsession (). setattribute ("imagemask", srand); // The image takes effect for graphics. dispose (); // output the image to the ImageIO page. write (image, "Jpeg", response. getoutputstream ();} // generate random color public color getrandcolor (int fc, int BC) {random = new random (); If (FC> 255) {fc = 255;} If (BC> 255) {BC = 255;} int r = FC + random. nextint (BC-Fc); int G = FC + random. nextint (BC-Fc); int B = FC + random. nextint (BC-Fc); return new color (R, G, B );}}