generating Authenticode via response
Verification Code:
Role: Preventing violent attacks
Click to change the JS code:
function changeimg (obj) {
Operation SRC Attribute
Obj.src= "/test/code?i=" +math.random ();
}
Code reference:
public class Codeservlet extends HttpServlet {public void doget (HttpServletRequest request, HttpServletResponse respons
E) throws Servletexception, IOException {//Using Java Graphical interface technology to draw a picture int charNum = 4;
int width = 30 * 4;
int height = 30; 1.
Create a picture of memory bufferedimage bufferedimage = new BufferedImage (width, height, bufferedimage.type_int_rgb);
2. Get the drawing object Graphics Graphics = Bufferedimage.getgraphics ();
3, draw the background color graphics.setcolor (color.yellow);
Graphics.fillrect (0, 0, width, height);
4, draw the picture border Graphics.setcolor (Color.Blue);
Graphics.drawrect (0, 0, width-1, height-1);
5, output verification code content Graphics.setcolor (color.red);
Graphics.setfont (New Font ("Song Body", Font.Bold, 20));
Randomly output 4 characters graphics2d graphics2d = (graphics2d) graphics;
String s = "ABCDEFGHGKLMNPQRSTUVWXYZ23456789";
Random Random = new Random ();
String msg = "" is used in the session;
int x = 5;
for (int i = 0; i < 4; i++) {int index = Random.nextint (32); String content = String.valueof (S.charat (index));
msg + content;
Double theta = Random.nextint (a) * math.pi/180;
Let the font twist graphics2d.rotate (theta, X, 18);
Graphics2d.drawstring (content, X, 18);
Graphics2d.rotate (-theta, X, 18);
x + 30;
}//6, Draw interference line Graphics.setcolor (Color.gray);
for (int i = 0; i < 5; i++) {int x1 = random.nextint (width);
int x2 = random.nextint (width);
int y1 = random.nextint (height);
int y2 = random.nextint (height);
Graphics.drawline (x1, y1, x2, y2);
}//release of resources graphics.dispose ();
Picture Output ImageIO imageio.write (bufferedimage, "JPG", Response.getoutputstream ());
public void DoPost (HttpServletRequest request, httpservletresponse response) throws Servletexception, IOException {
}
}