struts2图片显示

来源:互联网 发布:苏州java工资 编辑:程序博客网 时间:2024/06/01 17:05

struts2图片显示即是文件下载

一、配置struts.xml

        struts.xml中配置stream结果类型,并配置contentType、inputName、contentDisposition、bufferSize参数即可

<action name="readImgAction" class="com.bk.eserver.web.action.ImgAction" method="readImg" ><result type="stream"><param name="contentType">application/octet-stream</param><param name="inputName">inputStream</param> <param name="contentDisposition">attachment;filename=${fileName}</param>  <param name="bufferSize">4096</param></result></action>

二、ImgAction

public class ImgAction extends WebSupport {private InputStream inputStream;  /** * 读取图片 *  * @return */public String readImg() {try {inputStream = new FileInputStream(new File("D:\\meinv.jpg"));} catch (FileNotFoundException e) {e.printStackTrace();} return SUCCESS;}public InputStream getInputStream() {return inputStream;}public void setInputStream(InputStream inputStream) {this.inputStream = inputStream;}}

三、要显示图片的JSP

<img  src="admin/readImgAction.do">

恩,页面上将显示如下微笑



3 0
原创粉丝点击