com.sun.image.codec.jpeg.*,java.util.*" %>]]>
<%@ page autoflush="false" import="java.util.*,java.awt.*,
java.awt.image.*,com.sun.image.codec.jpeg.*,java.util.*" %>
<%
//set chinese char
//cody by ;
//homepage:jiarry.126.com
request.setcharacterencoding("gbk");
response.setcharacterencoding("gbk");
response.setcontenttype("text/html; charset=gbk");
%>
<%
string chose="0123456789abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz";
char display[]={'0',' ','0',' ','0',' ','0'},ran[]={'0','0','0','0'},temp;
random rand=new random();
for(int i=0;i<4;i )
{
temp=chose.charat(rand.nextint(chose.length()));
display[i*2]=temp;
ran[i]=temp;
}
string random=string.valueof(display);
session.setattribute("random",string.valueof(ran));
%>
<%
out.clear();
response.setcontenttype("image/jpeg");
response.addheader("pragma","no-cache");
response.addheader("cache-control","no-cache");
response.adddateheader("expries",0);
int width=80, height=30;
bufferedimage image = new bufferedimage(width, height,
bufferedimage.type_int_rgb);
graphics g = image.getgraphics();
//以下填充背景颜色
g.setcolor(color.green);
g.fillrect(0, 0, width, height);
//设置字体颜色
g.setcolor(color.red);
font font=new font("arial",font.plain,20);
g.setfont(font);
//g.drawstring(random,5,14);
g.drawstring(random,5,20);
g.dispose();
servletoutputstream outstream = response.getoutputstream();
jpegimageencoder encoder =jpegcodec.createjpegencoder(outstream);
encoder.encode(image);
outstream.close();
%>
|