Joke Collection Website - Blessing messages - Use java to randomly generate a four-digit verification code and find the programming code.
Use java to randomly generate a four-digit verification code and find the programming code.
& lt% @ page contenttype = "image/JPEG; charset = utf-8 " % & gt;
& lt%@page import="java.util.*,java.awt.*,java.awt.image.*,javax.imageio. * " % & gt
& lt% @ page import = " Java . io . output stream " % & gt;
& lthtml & gt
& ltbody & gt
& lt%!
Color getRandColor(int fc,int bc)
{
Random rd = new Random();
if(fc & gt; 255)fc = 255;
if(BC & gt; 255)BC = 255;
int red = fc+rd . nextint(BC-fc);
int green = fc+rd . nextint(BC-fc);
int blue = fc+rd . nextint(BC-fc);
Returns a new color (red, green, blue);
}
% & gt
& lt%
Random r = new Random();
Response.addHeader("Pragma ","no cache ");
response . add header(" Cache-Control "," no-Cache ");
response . adddate header(" expires ",0);
int width = 90
int height = 23
Buffered image pic = new buffered image (width, height, buffered image. TYPE _ INT _ RGB);
graphics GC = pic . get graphics();
gc.setColor(getRandColor(200,250));
gc.fillRect(0,0,width,height);
String[] rNum ={"0 "," 1 "," 2 "," 3 "," 4 "," 5 "," 6 "," 7 "," 8 "," 9 "," a "," b "," c "," d "," e "," f ",
" g "," h "," I "," j "," k "," l "," m "," n "," o "," p "," q "," r "," s "," t "," u "," v "," w ",
“x”,“y”,“z”,“A”,“B”,“C”,“D”,“E”,“F”,“G”,“H”,“I”,“J”,“K”,“L”,“M”,“N”,
“O”、“P”、“Q”、“R”、“S”、“T”、“U”、“V”、“W”、“X”、“Y”、“Z”};
int[] style = {Font。 Ordinary font. Bold, font. Italic, font. Plain color+font. Bold,
Font. Bold+font. Italic, font. Plain color+font. Italic, font. Plain color+font. Bold+font. Italic};
Gc.setColor (color. White);
gc.drawLine(0,30,90, 10);
GC . set color(getRandColor( 160,200));
for(int I = 0; I & lt50; i++)
{
Int x = r.nextInt (width);
int y = r . nextint(height);
int XL = r . nextint( 10);
int yl = r . nextint( 10);
gc.drawLine(x,y,x+xl,y+yl);
}
gc.setColor(getRandColor(60, 150));
String rt =
for(int I = 0; I<4; i++){
string temp = rNum[r . nextint(62)];
rt = rt+temp;
GC . set Font(New Font(" Times New Roman ",style[r.nextInt(7)], 15));
gc.drawString(temp,5+I * 15+r . nextint( 10), 10+r . nextint( 10));
}
GC . dispose();
session.setAttribute("randNum ",rt);
output stream OS = response . get output stream();
ImageIO.write(pic,“JPEG”,OS);
System.out.println ("current verification code is:"+session.getattribute ("randnum"));
OS . flush();
OS . close();
os = null
response . flush buffer();
out . clear();
out = pagecontext . push body();
% & gt
& lt/body & gt;
& lt/html & gt;
- Previous article:What if spam messages are recycled? What's the use?
- Next article:Blessings for children
- Related articles
- What tips will the court have for the thawing of WeChat?
- Teacher’s Day greetings from graduate students to their supervisors
- Classic quotations of patriotism, dedication, honesty and friendliness
- How to write self-recommendation of excellent employees?
- Does China Construction Bank need money to open mobile banking?
- Why is Apple Watch using Apple Pay different from iPhone?
- How to intercept my wife's mobile phone to send messages?
- Apply for a veterans' exclusive bank card?
- English Thanksgiving card for teachers.
- A brief message from the head teacher of the hundred-day oath