Struts2下载文件
2012-05-24 14:41
155 查看
Struts2下载文件实现的说明
contentType
内容类型,和互联网MIME标准中的规定类型一致,例如text/plain代表纯文本,text/xml表示XML,image/gif代表GIF图片,image/jpeg代表JPG图片
inputName
下载文件的来源流,对应着action类中某个类型为Inputstream的属性名,例如取值为inputStream的属性需要编写getInputStream()方法
contentDisposition
文件下载的处理方式,包括内联(inline)和附件(attachment)两种方式,而附件方式会弹出文件保存对话框,否则浏览器会尝试直接显示文件。取值为:
attachment;filename="struts2.txt",表示文件下载的时候保存的名字应为struts2.txt。如果直接写filename="struts2.txt",那么默认情况是代表inline,浏览器会尝试自动打开它,等价于这样的写法:inline;filename="struts2.txt"
bufferSize
下载缓冲区的大小
Struts2下载实现源代码
< ?xml version="1.0" encoding="UTF-8" ?>"-//ApacheSoftwareFoundation//DTD Struts Configuration 2.0//EN""<Ahref="http://struts.apache.org/dtds/struts-2.0.dtd">
http://struts.apache.org/dtds/struts-2.0.dtd< /A>">
< PACKAGE name="default" extends="struts-default"><!--在这里添加Action定义 -->
< !-- 简单文件下载 -->
< ACTIONclass=example.FileDownloadActionname="download">
< RESULT name="success" type="stream">
< M name="contentType">text/plain< /M>
< M name="inputName">inputStream< /M>
<Mname="contentDisposition">attachment;filename="struts2中文.txt"</M>
< M name="bufferSize">4096< /M>
< /RESULT>
< /ACTION>
< BR> < !-- 文件下载,支持中文附件名 -->
< ACTIONclass=example.FileDownloadAction2name="download2">
< !-- 初始文件名 -->
< M name="fileName">Struts中文附件.txt< /M>
< RESULT name="success" type="stream">
< M name="contentType">text/plain< /M>
< M name="inputName">inputStream< /M>
< !-- 使用经过转码的文件名作为下载文件名,downloadFileName属性
对应action类中的方法 getDownloadFileName() -->
<Mname="contentDisposition">attachment;filename="$downloadFileName"</M>
< M name="bufferSize">4096< /M>
< /RESULT>
< /ACTION>
< !-- 下载现有文件 -->
< ACTIONclass=example.FileDownloadAction3name="download3">
< M name="inputPath">/download/系统说明.doc< /M>
< !-- 初始文件名 -->
< M name="fileName">系统说明.doc< /M>
< RESULT name="success" type="stream">
<Mname="contentType">application/octet-stream;charset=ISO8859-1</M>
< M name="inputName">inputStream< /M>
< !-- 使用经过转码的文件名作为下载文件名,downloadFileName属性
对应action类中的方法 getDownloadFileName() -->
<Mname="contentDisposition">attachment;filename="$downloadFileName"</M>
< M name="bufferSize">4096< /M>
< /RESULT>
< /ACTION>
< /PACKAGE>
contentType
内容类型,和互联网MIME标准中的规定类型一致,例如text/plain代表纯文本,text/xml表示XML,image/gif代表GIF图片,image/jpeg代表JPG图片
inputName
下载文件的来源流,对应着action类中某个类型为Inputstream的属性名,例如取值为inputStream的属性需要编写getInputStream()方法
contentDisposition
文件下载的处理方式,包括内联(inline)和附件(attachment)两种方式,而附件方式会弹出文件保存对话框,否则浏览器会尝试直接显示文件。取值为:
attachment;filename="struts2.txt",表示文件下载的时候保存的名字应为struts2.txt。如果直接写filename="struts2.txt",那么默认情况是代表inline,浏览器会尝试自动打开它,等价于这样的写法:inline;filename="struts2.txt"
bufferSize
下载缓冲区的大小
Struts2下载实现源代码
< ?xml version="1.0" encoding="UTF-8" ?>"-//ApacheSoftwareFoundation//DTD Struts Configuration 2.0//EN""<Ahref="http://struts.apache.org/dtds/struts-2.0.dtd">
http://struts.apache.org/dtds/struts-2.0.dtd< /A>">
< PACKAGE name="default" extends="struts-default"><!--在这里添加Action定义 -->
< !-- 简单文件下载 -->
< ACTIONclass=example.FileDownloadActionname="download">
< RESULT name="success" type="stream">
< M name="contentType">text/plain< /M>
< M name="inputName">inputStream< /M>
<Mname="contentDisposition">attachment;filename="struts2中文.txt"</M>
< M name="bufferSize">4096< /M>
< /RESULT>
< /ACTION>
< BR> < !-- 文件下载,支持中文附件名 -->
< ACTIONclass=example.FileDownloadAction2name="download2">
< !-- 初始文件名 -->
< M name="fileName">Struts中文附件.txt< /M>
< RESULT name="success" type="stream">
< M name="contentType">text/plain< /M>
< M name="inputName">inputStream< /M>
< !-- 使用经过转码的文件名作为下载文件名,downloadFileName属性
对应action类中的方法 getDownloadFileName() -->
<Mname="contentDisposition">attachment;filename="$downloadFileName"</M>
< M name="bufferSize">4096< /M>
< /RESULT>
< /ACTION>
< !-- 下载现有文件 -->
< ACTIONclass=example.FileDownloadAction3name="download3">
< M name="inputPath">/download/系统说明.doc< /M>
< !-- 初始文件名 -->
< M name="fileName">系统说明.doc< /M>
< RESULT name="success" type="stream">
<Mname="contentType">application/octet-stream;charset=ISO8859-1</M>
< M name="inputName">inputStream< /M>
< !-- 使用经过转码的文件名作为下载文件名,downloadFileName属性
对应action类中的方法 getDownloadFileName() -->
<Mname="contentDisposition">attachment;filename="$downloadFileName"</M>
< M name="bufferSize">4096< /M>
< /RESULT>
< /ACTION>
< /PACKAGE>
相关文章推荐
- struts2 文件下载
- Struts2总结---文件上传和下载详解 (9)
- 11、Struts2 的文件上传和下载
- struts2下载文件
- 【J2EE核心开发学习笔记 012】Struts2文件的上传与下载
- struts2 实现中文文件名的文件下载
- struts2文件下载功能实现(文件名中文转码)
- day29-struts2---day04( 文件上传,下载,token令牌机制,值栈强调)
- struts2 文件下载方式 此法解决下载中文文件问题
- Struts2实现文件的上传与动态下载功能。
- Struts2之文件下载
- Struts2 框架实现多文件上传下载
- struts2文件下载
- struts2文件上传与下载
- Struts2之文件下载
- struts2文件下载及 <param name="inputName">inputStream</param>的理解
- Struts2文件下载 (来源thisliy-->感谢分享)
- struts2学习(13)struts2文件上传和下载(1)
- Struts2文件上传与下载(中文名称的文件正常上传与下载)
- 11、Struts2 的文件上传和下载