Servlet動態(tài)產(chǎn)生JPEG圖像的例子_JSP教程
推薦:jsp 自定義分頁標(biāo)簽花了一上午簡單研究了下自定義標(biāo)簽。就弄了個自定義的分頁標(biāo)簽。代碼沒有怎么仔細優(yōu)化。先貼上來,:) 1,標(biāo)簽的實現(xiàn)類NumenTag.java import java.util.ArrayList;import java.util.Has
//GenerateImage.java
/* 動態(tài)產(chǎn)生JPEG圖像的例子 */
import java.awt.*;
import java.awt.image.*;
import com.sun.image.codec.jpeg.*; //編碼類
java.util.*;
javax.servlet.*;
javax.servlet.http.*;
java.io.*;
class GenerateImage extends HttpServlet
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException, java.io.IOException {
response.setContentType("image/jpeg"):
int width=200, height=200;
BufferedImage image = BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
Graphics g = image.getGraphics();
g.setColor(Color.white);
g.fillRect(0,0,width,heitht);
Polygon poly = new Polygon();
Random random = new Random();
for(int i=0;i<5;i )
{
poly.addPoint(random.nextInt(width),random.nextInt(height));
}
g.setColor(Color.cyan);
g.fillPolygon(poly);
g.dispose(); //消拙Graphics 對圖形沒有肖毀
ServletOutputStream sos =response.getOutputStream(); //二進制
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(sos); //創(chuàng)建編碼器,輸出到sos那里
encoder.encode(image);
}
public void doPost(HttpServletRequest request,HttpServletResponse response)
throws ServletException, java.io.IOException {
doGet(request,response);
}
}
http://blog.csdn.net/laiahu/archive/2007/01/23/1491681.aspx
分享:JSP Struts之HTML標(biāo)簽庫詳解JSP Struts之HTML標(biāo)簽庫詳解Struts提供了五個標(biāo)簽庫,即:HTML、Bean、Logic、Template和Nested。 標(biāo)簽庫 說明 HTML 標(biāo)簽 用來創(chuàng)建能夠和Struts 框架和其他相應(yīng)的HTML 標(biāo)簽交互的HTML 輸
- jsp response.sendRedirect不跳轉(zhuǎn)的原因分析及解決
- JSP指令元素(page指令/include指令/taglib指令)復(fù)習(xí)整理
- JSP腳本元素和注釋復(fù)習(xí)總結(jié)示例
- JSP FusionCharts Free顯示圖表 具體實現(xiàn)
- 網(wǎng)頁模板:關(guān)于jsp頁面使用jstl的異常分析
- JSP頁面中文傳遞參數(shù)使用escape編碼
- 基于jsp:included的使用與jsp:param亂碼的解決方法
- Java Web項目中連接Access數(shù)據(jù)庫的配置方法
- JDBC連接Access數(shù)據(jù)庫的幾種方式介紹
- 網(wǎng)站圖片路徑的問題:絕對路徑/虛擬路徑
- (jsp/html)網(wǎng)頁上嵌入播放器(常用播放器代碼整理)
- jsp下顯示中文文件名及絕對路徑下的圖片解決方法
- 相關(guān)鏈接:
- 教程說明:
JSP教程-Servlet動態(tài)產(chǎn)生JPEG圖像的例子
。