`
234390216
  • 浏览: 10194721 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
博客专栏
A5ee55b9-a463-3d09-9c78-0c0cf33198cd
Oracle基础
浏览量:460857
Ad26f909-6440-35a9-b4e9-9aea825bd38e
springMVC介绍
浏览量:1771924
Ce363057-ae4d-3ee1-bb46-e7b51a722a4b
Mybatis简介
浏览量:1395534
Bdeb91ad-cf8a-3fe9-942a-3710073b4000
Spring整合JMS
浏览量:393930
5cbbde67-7cd5-313c-95c2-4185389601e7
Ehcache简介
浏览量:678275
Cc1c0708-ccc2-3d20-ba47-d40e04440682
Cas简介
浏览量:529339
51592fc3-854c-34f4-9eff-cb82d993ab3a
Spring Securi...
浏览量:1178824
23e1c30e-ef8c-3702-aa3c-e83277ffca91
Spring基础知识
浏览量:462093
4af1c81c-eb9d-365f-b759-07685a32156e
Spring Aop介绍
浏览量:150186
2f926891-9e7a-3ce2-a074-3acb2aaf2584
JAXB简介
浏览量:66908
社区版块
存档分类
最新评论

struts2文件下载

阅读更多

 

 

 

 

<action name="test" class="com.TestAction" method="importToFile">
    	<result name="success" type="stream">    
        <param name="contentType">unknown</param>    
        <param name="inputName">downloadFile</param> <!--下载文件的文件流名称,在action中需要给它一个get方法返回下载文件的流-->   
        <param name="contentDisposition">attachment;filename="${downloadFileName}"</param>  
        <param name="bufferSize">4096</param>    
    </result>   
    </action>

 

 

public InputStream getDownloadFile() throws InvalidResultSetAccessException, IOException, SQLException {
		String path = request.getSession().getServletContext().getRealPath("/temp");
		File dir = new File(path);
		if (!dir.exists())
			dir.mkdir();
		parent_code = request.getParameter("parent_code");
		String fileName = "shopbarcode_"+parent_code+".txt";
		File file = new File(dir,fileName);
		FileWriter writer = new FileWriter(file);
		DB db = new DB();
		writeToFile(db, writer, parent_code);
		writer.close();
		return ServletActionContext.getServletContext().getResourceAsStream("/temp/"+fileName);
	}


public String importToFile() {
		setDownloadFileName("test.txt");
		return SUCCESS;
	}

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics