Random. jsp (preferred for SUN Enterprise Applications) file code:
<% @ Page autoFlush = "false" import = "java. awt. *, java. awt. image. *, com.sun.image.codec.jpeg. *, java. util. *" %>
<% @ Page import = "org. apache (the most popular WEB server platform on Unix). commons. lang. RandomStringUtils" %>
<%
RandomStringUtils rs = new RandomStringUtils ();
String random = rs. randomAlphanumeric (4 );
Session. setAttribute ("random", random );
%>
<%
Out. clear ();
Response. setContentType ("image/jpeg ");
Response. addHeader ("pragma", "NO-cache ");
Response. addHeader ("Cache-Control", "no-cache ");
Response. addDateHeader ("Expries", 0 );
Int width = 100, height = 40;
BufferedImage image = new BufferedImage (width, height, BufferedImage. TYPE_INT_RGB );
Graphics g = image. getGraphics ();
// Fill in the following background? Color
G. setColor (Color. GRAY );
Font DeFont = new Font ("SansSerif", Font. PLAIN, 32 );
G. setFont (DeFont );
G. fillRect (0, 0, width, height );
//? Font? Color
G. setColor (Color. RED );
G. drawString (random, 3,30 );
G. dispose ();
ServletOutputStream outStream = response. getOutputStream ();
Required imageencoder encoder = required codec. createJPEGEncoder (outStream );
Encoder. encode (image );
OutStream. close ();
%>
The code for the test. jsp file (preferred for SUN Enterprise Applications) is as follows:
<% @ Page contentType = "text/html; charset = UTF-8" language = "java" import = "java. SQL. *" errorPage = "" %>
<Html>
<Head>
<Title> Untitled Document </title>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
</Head>
<Body>
</Body>
</Html>
If you do not want to import apache (the most popular WEB server platform on Unix) packages, You can compile the following file by yourself.
// FrontEnd Plus GUI for JAD
// DeCompiled: RandomStringUtils. class
Package org. apache (the most popular WEB server platform on the Unix platform). commons. lang;
Import java. util. Random;
Public class RandomStringUtils
{
Private static final Random RANDOM = new Random ();
Public RandomStringUtils ()
{
}
Public static String random (int count)
{
Return random (count, false, false );
}
Public static String randomAscii (int count)
{
Return random (count, 32,127, false, false );