一、jsp 頁面html
<html xmlns="http://www.w3.org/1999/xhtml">web
<head>app
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />jsp
<title>Insert title here</title>ui
</head>url
<body>xml
<div>htm
</div>ip
<div>get
<img src="ImgShowServlet.servlet" alt="" />
</div>
</body>
</html>
二、web.xml 配置
<servlet>
<description></description>
<display-name>ImgShowServlet</display-name>
<servlet-name>ImgShowServlet</servlet-name>
<servlet-class>com.jcc.demo.img2ie.servlet.ImgShowServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ImgShowServlet</servlet-name>
<url-pattern>/ImgShowServlet.servlet</url-pattern>
</servlet-mapping>
三、servlet代碼
protected void service(HttpServletRequest arg0, HttpServletResponse response) throws ServletException, IOException {
System.out.println("get the request from ie.");
ServletOutputStream os = response.getOutputStream();
File file = new File("D:/demo/111.jpg");
if(file.exists()){
BufferedImage readImg = ImageIO.read(file);
ImageIO.write(readImg, "JPEG", os);
}
os.close();
}