站内搜索: 请输入搜索关键词

当前页面: 开发资料首页JSP 专题JSP中在内存中生成的图片显示到页面中

JSP中在内存中生成的图片显示到页面中

摘要: 图片 页面
<table style="TABLE-LAYOUT: fixed" cellSpacing=0 cellPadding=0 border=0> <tr> <td>

下载:点击下载
演示:本站暂时不支持JSP空间


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");
%>

<head>
Http://www.lionsky.net

</head>
<body>
<form id="Form1" method="post">
<input type="text" id="ID_Text" name=ID_Text>
<input type=submit value="GO">
</form>
</body>

<%
}
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();
//以下填充背景颜色
g.setColor(Color.lightGray);
g.fillRect(0, 0, width, height);
String random="random";
//以下设置前景色
g.setColor(Color.BLACK);
g.drawString("Http://www.lionsky.net",10,20);
g.drawString("Author:Lion[lion-a@sohu.com]",10,40);
g.drawLine(10,50,290,50);
g.drawString(ImageStr,10,70);
g.dispose();
ServletOutputStream outStream = response.getOutputStream();
JPEGImageEncoder encoder =JPEGCodec.createJPEGEncoder(outStream);
encoder.encode(image);
outStream.close();
}

%>

</td></tr></table>



↑返回目录
前一篇: Jsp小结1,2点
后一篇: 在JSP中实现DES加密解密的例子