日期:2014-05-16 浏览次数:20355 次
<?xml version="1.0" encoding="UTF-8" ?> <%@page import="java.awt.image.BufferedImage"%> <%@page import="javax.imageio.ImageIO"%> <%@page import="org.apache.commons.io.IOUtils"%> <%@page import="java.io.InputStream"%> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>读取服务器上的文件</title> </head> <body> <% InputStream in = getServletContext().getResourceAsStream( "/upload/111.jpg"); BufferedImage bfi = ImageIO.read(in); response.reset();//清除buffer response.setContentType("image/gif"); ImageIO.write(bfi, "jpg", response.getOutputStream()); out.clear(); out = pageContext.pushBody(); %> </body> </html>
<?xml version="1.0" encoding="UTF-8" ?> <%@page import="org.apache.commons.io.IOUtils"%> <%@page import="java.io.InputStream"%> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>读取上传文件</title> </head> <body> <% InputStream in = getServletContext().getResourceAsStream( "/upload/HIBERNATE.txt"); out.println(IOUtils.toString(in)); %> </body> </html>