09-11
13
jsp输出静态的图片
作者:Java伴侣 日期:2009-11-13
两个方式,jsp中直接输出静态图片:
img.jsp
<%@page import="javax.imageio.*"%>
<%@page import="java.awt.image.BufferedImage,java.io.*;"%>
img2.jsp
img.jsp
<%@page import="javax.imageio.*"%>
<%@page import="java.awt.image.BufferedImage,java.io.*;"%>
复制内容到剪贴板 程序代码
<%
File myGifFile = new File("e:\\aa\\haha.gif");
BufferedImage bufi = ImageIO.read(myGifFile);
response.reset();
response.setContentType("image/gif");
ImageIO.write(bufi, "gif", response.getOutputStream());
%>
File myGifFile = new File("e:\\aa\\haha.gif");
BufferedImage bufi = ImageIO.read(myGifFile);
response.reset();
response.setContentType("image/gif");
ImageIO.write(bufi, "gif", response.getOutputStream());
%>
img2.jsp
复制内容到剪贴板 程序代码
<%@page import="java.io.*;"%>
<%
response.reset();
response.setContentType("image/gif");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
java.io.FileInputStream fis = new java.io.FileInputStream(new File("e:\\aa\\haha.gif"));
java.io.OutputStream os = response.getOutputStream();
byte[] buf = new byte[4096];
int bytes = 0;
while ((bytes = fis.read(buf)) != -1)
os.write(buf, 0, bytes);
fis.close();
%>
<%
response.reset();
response.setContentType("image/gif");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
java.io.FileInputStream fis = new java.io.FileInputStream(new File("e:\\aa\\haha.gif"));
java.io.OutputStream os = response.getOutputStream();
byte[] buf = new byte[4096];
int bytes = 0;
while ((bytes = fis.read(buf)) != -1)
os.write(buf, 0, bytes);
fis.close();
%>
评论: 0 | 引用: 0 | 查看次数: 349
发表评论