请问我的代码为什么不能输出jpg图像呢?(代码见内)

katt 03-01-06

<%@ page contentType="image/jpeg"
import="java.awt.*,
java.awt.image.*,
com.sun.image.codec.jpeg.*,
java.util.*,
java.awt.Graphics2D.*,
javax.servlet.http.HttpServletResponse
"
%>

<%


int width=200, height=200;
BufferedImage image = new BufferedImage(300,300,BufferedImage.TYPE_INT_RGB);


Graphics2D g=image.createGraphics();


g.setColor(Color.white);
g.fillRect(0, 0, width, height);


g.setColor(Color.cyan);
g.fill3DRect(50,50,20,10,true);

g.dispose();

try{
ServletOutputStream sos=response.getOutputStream();
JPEGImageEncoder encoder=JPEGCodec.createJPEGEncoder(sos);
encoder.encode(image);


}catch (Exception e){
System.out.println("image出错" + e.getMessage());

}
sos.close();

%>