Instructor: Beida Jade Bird five crossing original Ngoc Minh
Attach a sheet first:
Knowledge points need to be mastered: Ajax and layer verification codes
Knowledge Mastery: Ajax
Ajax is not a new programming language, but rather a technique for creating better, faster, and more interactive Web applications. Use JavaScript to make requests to the server and handle the response without blocking the user! Core Object XMLHttpRequest. With this object, your JavaScript can exchange data with the Web server without overloading the page. AJAX uses asynchronous data transfer (HTTP requests) between the browser and the Web server, which allows the Web page to request a small amount of information from the server, rather than the entire page. AJAX can make Internet applications smaller, faster, and friendlier.How AJAX worksAJAX is a browser technology that is independent of WEB server software. AJAX is based on the following WEB standards:JavaScriptXMLHTMLcss inThe WEB standards used in AJAX have been well-defined and supported by all major browsers. AJAX applications are independent of browsers and platforms. WEB applications have many advantages over desktop applications, they can involve a wide range of users, they are easier to install and maintain, and are more easily developed. However, Internet applications are not as perfect and friendly as traditional desktop applications. With AJAX, Internet applications can become more complete and friendlier.Layer:Layer, a Web popup (layer) solution (JS component) that can make you think of it, author Yin Xin (front- end development engineer ). Layer focuses on the user's flexible customization, which provides the power for different people to use their habits. The point is that you can make your pages richer and more convenient, and you simply configure the relevant parameters when you call them, and it's easy to implement. The benefits of layer are obvious compared to similar pop-up layer components, and she is as much more robust as possible in less code. Layer is particularly focused on performance improvements, in multi-layer mode callback processing, with the other majority of components do not have "independent conflict" (as of October 2013 23, there are
115859 people concerned about the new layer). You can safely pop up any number of layers on the page, and they don't interfere with each other. When asked about her compatibility, the layer must tell you that she is compatible with all browsers, including the old IE6. layer exposes so many interfaces (APIs) that you can DIY too much of the style you need, especially in the page layer mode, meaning you can completely discard the existing skin of the layer when necessary and use your mind to outline her dress. The problem is that I have to stop the "Wang Po selling melon" statement. Because of the lack of all or friendly, you need to use the process to find. incomplete statistics, as of August 30, 2013, layer has been serving more than
6000 web platform. Layer as a member of the Layui library, will always be dedicated to providing the power for web development.
Verification Code:
Package Cn.weilengdeyu.easybuy.web;import Java.awt.color;import java.awt.font;import java.awt.graphics;import Java.awt.image.bufferedimage;import Java.io.ioexception;import Java.io.printwriter;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 classNum extends HttpServlet { Public voiddoget (httpservletrequest request, httpservletresponse response) throws Servletexception, IOException { DoPost (Request,response); } Public voidDoPost (httpservletrequest request, httpservletresponse response) throws Servletexception, IOException { //Settings page does not cacheResponse.setheader ("Pragma","No-cache"); Response.setheader ("Cache-control","No-cache"); Response.setdateheader ("Expires",0); //Create an image in memory intwidth = -, height = -; BufferedImage Image=Newbufferedimage (width, height, bufferedimage.type_int_rgb); //Get the graphics contextGraphics g =Image.getgraphics (); //Generating Random classesRandom random =NewRandom (); //Set Background colorG.setcolor (Getrandcolor ( $, -)); G.fillrect (0,0, width, height); //Set FontG.setfont (NewFont ("Times New Roman", Font.plain, -)); //Draw Border//G.setcolor (New Color ()); //G.drawrect (0,0,width-1,height-1); G.setcolor (Getrandcolor ( the, $)); //randomly generates 155 lines of interference so that the authentication code in the image is not easily detected by other programs for(inti =0; I <155; i++) { intx =random.nextint (width); inty =random.nextint (height); intXL = Random.nextint ( A); intYL = Random.nextint ( A); G.drawline (x, y, x+ XL, Y +yl); } //randomly generated authentication code (4 digits)String SRand =""; for(inti =0; I <4; i++) {String rand= String.valueof (Random.nextint (Ten)); SRand+=Rand; //Display the authentication code to the imageG.setcolor (NewColor ( -+ Random.nextint ( the), -+random. Nextint ( the), -+ Random.nextint ( the)));//The call function comes out with the same color, possibly because the seed is too close, so it can only be generated directlyg.DrawString (Rand, -* i +6, -); } //Save authentication Code to sessionRequest.getsession (). SetAttribute ("Numrand", SRand); //Image EffectiveG.dispose (); //output image to pageImageio.write (Image,"JPEG", Response.getoutputstream ()); } PublicColor Getrandcolor (intFcintBC) {//get random colors for a given rangeRandom random =NewRandom (); if(FC >255) FC=255; if(BC >255) BC=255; intr = FC + random.nextint (BC-FC); intg = FC + random.nextint (BC-FC); intB = fc + random.nextint (BC-FC); return NewColor (R, G, b); }}
View Code
"Huang Fu"? Easy to buy Network _ Login Module