JSP頁面路徑
<img src="showimg.action">
struts.xml配置
<action name="showimg" class="com.test.userinfo.action.ShowImgAction">
</action>
action code
public class ShowImgAction extends MyActionSuport{
private static final long serialVersionUID = 1L;
public String execute() throws Exception {
//方法一
// URL url=new URL("http://127.0.0.1:8080/eprintGlobal/images/body_top_left.gif");
// Image image = ImageIO.read(url);
// 方法二
File file = new File("F:\\1.jpg");
InputStream is = new FileInputStream(file);
Image image = ImageIO.read(is);//读图片
RenderedImage img=(RenderedImage) image;
ImageIO.write(img, "jpeg", response.getOutputStream());
return null;
}
}