zoukankan      html  css  js  c++  java
  • struts2图片显示

    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">

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



  • 相关阅读:
    决策树
    交叉熵与softmax
    集成学习
    SVM算法
    蒙特卡罗方法
    K近邻--KNN
    K-Means聚类
    DBSCAN密度聚类
    Bagging、随机森林
    支持向量机SVM
  • 原文地址:https://www.cnblogs.com/itmyhome/p/4131328.html
Copyright © 2011-2022 走看看