Question about the servlet Verification Code under LINUXG
Source: Internet
Author: User
For more information about the servlet Verification Code under LINUXG-Linux Enterprise Application-Linux server application, see the following. Our project uses struts1.2. I used sertlet to write a program to generate verification,
BufferedImage buffImg = new BufferedImage (width, height, BufferedImage. TYPE_INT_RGB );
Graphics2D g = buffImg. createGraphics ();
G. setColor (Color. WHITE );
G. fillRect (0, 0, width, height );
Font font = new Font ("Times New Roman", Font. PLAIN, 18 );
G. setFont (font );
G. setColor (Color. BLACK );
G. drawRect (0, 0, width-1, height-1 );
G. setColor (Color. GRAY );
Random random = new Random ();
For (int I = 0; I <40; I ++ ){
Int x1 = random. nextInt (width );
Int y1 = random. nextInt (height );
Int x2 = random. nextInt (10 );
Int y2 = random. nextInt (10 );
G. drawLine (x1, y1, x1 + x2, y1 + y2 );
}
StringBuffer randomCode = new StringBuffer ();
For (int I = 0; I <4; I ++ ){
String strRand = String. valueOf (random. nextInt (10 ));
G. setColor (Color. RED );
G. drawString (strRand, 13 * I + 6, 16 );
RandomCode. append (strRand );
}
// Put the verification code in the cookie
CookieHelper. setCookie (response, "random", randomCode. toString ());
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.