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>
<頭>
<title>http://www.lionsky.net</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</頭>
<正文>
<form id="Form1" method="post">
<輸入類型=“文字”id=“ID_Text”名稱=ID_Text>
<輸入類型=提交值=“GO”>
</形式>
</正文>
</HTML>
<%
}
別的
{
輸出.clear();
響應.setContentType(“圖像/jpeg”);
response.addHeader("pragma","NO-cache");
response.addHeader("快取控制","無快取");
response.addDateHeader("Expries",0);
int 寬度=300,高度=100;
BufferedImage 映像 = new BufferedImage(寬度, 高度, BufferedImage.TYPE_INT_RGB);
圖形 g = image.getGraphics();
//以下填滿背景顏色
g.setColor(Color.lightGray);
g.fillRect(0, 0, 寬度, 高度);
字串隨機=“隨機”;
//以下設定前方景色
g.setColor(Color.BLACK);
g.drawString(" http://www.downcodes.com",10,20 );
g.drawString("作者:Lion[[email protected]]",10,40);
g.drawLine(10,50,290,50);
g.drawString(ImageStr,10,70);
g.dispose();
ServletOutputStream outStream = response.getOutputStream();
JPEGImageEncoder編碼器=JPEGCodec.createJPEGEncoder(outStream);
編碼器.編碼(圖像);
outStream.close();
}
%>