现在的位置: 首页 > 综合 > 正文

文件下载

2013年08月29日 ⁄ 综合 ⁄ 共 515字 ⁄ 字号 评论关闭

1、action中

        

private InputStream inputStream; // getter与setter

	public String download() throws Exception {
		// 指定要下载的文件
		inputStream = new FileInputStream(filePath);

		// 指定默认的文件名(使用URL编码解决中文件乱码问题)
		String fileName = URLEncoder.encode(template.getName(), "utf-8");
		ActionContext.getContext().put("fileName", fileName);

		return "download";
	}

2、struts.xml

<result name="downloadProcessImage" type="stream">
		<param name="inputName">inputStream</param>
		<!-- 指定下载文件的默认文件名 -->
		<param name="contentDisposition">attachment;filename="${#fileName}.doc"</param>	
	</result>

抱歉!评论已关闭.