jsp显示静态图片

jsp里面的引用:

 

Image.jsp

<%@ page contentType="image/jpeg"%> <%@ page language="java"  import="java.io.*"%> <%

out.clear(); response.setContentType("image/jpeg"); response.addHeader("pragma","NO-cache"); response.addHeader("Cache-Control","no-cache"); response.addDateHeader("Expries",0);    String str="c:/4.jpg";    byte[] myData = null;        InputStream input = new FileInputStream(str);     try      {        ByteArrayOutputStream byteArray = new ByteArrayOutputStream();        int ch = 0;        while ((ch = input.read()) != -1)        {          byteArray.write(ch);        }          myData = byteArray.toByteArray();      }      catch (RuntimeException e)      {              e.printStackTrace();       throw e;      }     myData =  new sun.misc.BASE64Decoder().decodeBuffer(new sun.misc.BASE64Encoder().encode(myData));  System.out.println("myDate.length()="+myData.length);  OutputStream toClient=response.getOutputStream();  toClient.write(myData);      toClient.close();  %>

 

你可能感兴趣的:(jsp显示静态图片)