Imaging_toweb.jsp
<% @ Page autoflush = "false" Import = "Java. AWT. *, java. AWT. image. *, com.sun.image.codec.jpeg. *, java. util. *" %>
<%
String imagestr = request. getparameter ("id_text ");
If (imagestr = NULL | imagestr. Equals (""))
{
Response. setcontenttype ("text/html; charset = gb2312 ");
%>
<HTML>
<Head>
<Title> http: // www.lionsky.net </title>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
</Head>
<Body>
<Form ID = "form1" method = "Post">
<Input type = "text" id = "id_text" name = id_text>
<Input type = submit value = "go">
</Form>
</Body>
</Html>
<%
}
Else
{
Out. Clear ();
Response. setcontenttype ("image/JPEG ");
Response. addheader ("Pragma", "No-Cache ");
Response. addheader ("cache-control", "No-Cache ");
Response. adddateheader ("expries", 0 );
Int width = 300, Height = 100;
Bufferedimage image = new bufferedimage (width, height, bufferedimage. type_int_rgb );
Graphics G = image. getgraphics ();
// Fill in the background color below
G. setcolor (color. lightgray );
G. fillrect (0, 0, width, height );
String random = "random ";
// Set the foreground color below
G. setcolor (color. Black );
G. drawstring ("http: // www.knowsky.com", 10, 20 );
G. drawstring ("Author: Lion [lion-a@sohu.com );
G. drawline );
G. drawstring (imagestr, 10, 70 );
G. Dispose ();
Servletoutputstream outstream = response. getoutputstream ();
Required imageencoder encoder = required codec. createjpegencoder (outstream );
Encoder. encode (image );
Outstream. Close ();
}
%>