(转)
Struts2 contentType属性列表
'ez' => 'application/andrew-inset',
'hqx' => 'application/mac-binhex40',
'cpt' => 'application/mac-compactpro',
'doc' => 'application/msword',
'bin' => 'application/octet-stream',
'dms' => 'application/octet-stream',
'lha' => 'application/octet-stream',
'lzh' => 'application/octet-stream',
'exe' => 'application/octet-stream',
'class' => 'application/octet-stream',
'so' => 'application/octet-stream',
'dll' => 'application/octet-stream',
'oda' => 'application/oda',
'pdf' => 'application/pdf',
'ai' => 'application/postscript',
'eps' => 'application/postscript',
'ps' => 'application/postscript',
'smi' => 'application/smil',
'smil' => 'application/smil',
'mif' => 'application/vnd.mif',
'xls' => 'application/vnd.ms-excel',
'ppt' => 'application/vnd.ms-powerpoint',
'wbxml' => 'application/vnd.wap.wbxml',
'wmlc' => 'application/vnd.wap.wmlc',
'wmlsc' => 'application/vnd.wap.wmlscriptc',
'bcpio' => 'application/x-bcpio',
'vcd' => 'application/x-cdlink',
'pgn' => 'application/x-chess-pgn',
'cpio' => 'application/x-cpio',
'csh' => 'application/x-csh',
'dcr' => 'application/x-director',
'dir' => 'application/x-director',
'dxr' => 'application/x-director',
'dvi' => 'application/x-dvi',
'spl' => 'application/x-futuresplash',
'gtar' => 'application/x-gtar',
'hdf' => 'application/x-hdf',
'js' => 'application/x-javas
cript',
'skp' => 'application/x-koan',
'skd' => 'application/x-koan',
'skt' => 'application/x-koan',
'skm' => 'application/x-koan',
'latex' => 'application/x-latex',
'nc' => 'application/x-netcdf',
'cdf' => 'application/x-netcdf',
'sh' => 'application/x-sh',
'shar' => 'application/x-shar',
'swf' => 'application/x-shockwave-flash',
'sit' => 'application/x-stuffit',
'sv4cpio' => 'application/x-sv4cpio',
'sv4crc' => 'application/x-sv4crc',
'tar' => 'application/x-tar',
'tcl' => 'application/x-tcl',
'tex' => 'application/x-tex',
'texinfo' => 'application/x-texinfo',
'texi' => 'application/x-texinfo',
't' => 'application/x-troff',
'tr' => 'application/x-troff',
'roff' => 'application/x-troff',
'man' => 'application/x-troff-man',
'me' => 'application/x-troff-me',
'ms' => 'application/x-troff-ms',
'ustar' => 'application/x-ustar',
'src' => 'application/x-wais-source',
'xhtml' => 'application/xhtml+xml',
'xht' => 'application/xhtml+xml',
'zip' => 'application/zip',
'au' => 'audio/basic',
'snd' => 'audio/basic',
'mid' => 'audio/midi',
'midi' => 'audio/midi',
'kar' => 'audio/midi',
'mpga' => 'audio/mpeg',
'mp2' => 'audio/mpeg',
'mp3' => 'audio/mpeg',
'aif' => 'audio/x-aiff',
'aiff' => 'audio/x-aiff',
'aifc' => 'audio/x-aiff',
'm3u' => 'audio/x-mpegurl',
'ram' => 'audio/x-pn-realaudio',
'rm' => 'audio/x-pn-realaudio',
'rpm' => 'audio/x-pn-realaudio-plugin',
'ra' => 'audio/x-realaudio',
'wav' => 'audio/x-wav',
'pdb' => 'chemical/x-pdb',
'xyz' => 'chemical/x-xyz',
'bmp' => 'image/bmp',
'gif' => 'image/gif',
'ief' => 'image/ief',
'jpeg' => 'image/jpeg',
'jpg' => 'image/jpeg',
'jpe' => 'image/jpeg',
'png' => 'image/png',
'tiff' => 'image/tiff',
'tif' => 'image/tiff',
'djvu' => 'image/vnd.djvu',
'djv' => 'image/vnd.djvu',
'wbmp' => 'image/vnd.wap.wbmp',
'ras' => 'image/x-cmu-raster',
'pnm' => 'image/x-portable-anymap',
'pbm' => 'image/x-portable-bitmap',
'pgm' => 'image/x-portable-graymap',
'ppm' => 'image/x-portable-pixmap',
'rgb' => 'image/x-rgb',
'xbm' => 'image/x-xbitmap',
'xpm' => 'image/x-xpixmap',
'xwd' => 'image/x-xwindowdump',
'igs' => 'model/iges',
'iges' => 'model/iges',
'msh' => 'model/mesh',
'mesh' => 'model/mesh',
'silo' => 'model/mesh',
'wrl' => 'model/vrml',
'vrml' => 'model/vrml',
'css' => 'text/css',
'html' => 'text/html',
'htm' => 'text/html',
'asc' => 'text/plain',
'txt' => 'text/plain',
'rtx' => 'text/richtext',
'rtf' => 'text/rtf',
'sgml' => 'text/sgml',
'sgm' => 'text/sgml',
'tsv' => 'text/tab-separated-values',
'wml' => 'text/vnd.wap.wml',
'wmls' => 'text/vnd.wap.wmlscript',
'etx' => 'text/x-setext',
'xsl' => 'text/xml',
'xml' => 'text/xml',
'mpeg' => 'video/mpeg',
'mpg' => 'video/mpeg',
'mpe' => 'video/mpeg',
'qt' => 'video/quicktime',
'mov' => 'video/quicktime',
'mxu' => 'video/vnd.mpegurl',
'avi' => 'video/x-msvideo',
'movie' => 'video/x-sgi-movie',
'ice' => 'x-conference/x-cooltalk'
通常使用application/octet-stream 即可
以上是转载部分,谢谢作者。
最近做了一个项目,下载的的文件其他格式(cad文件,.dwg格式),于是上面的内容,将下载类型设置成 "application/octet-stream", 系统可以下载。特此记录一下
页面下载文件链接:<a href="download.action?fileName=test.dwg">下载文件</a>
struts2.xml配置action:
<action name="download" class="com.action.XXXAction" >
<result type="stream">
<param name="contentType">application/octet-stream</param>
<!-- inputName要与action中方法对应去掉 get ( action的getDownloadFile()方法 ) -->
<param name="inputName">downloadFile</param>
<param name="bufferSize">10000</param>
<!-- 此处必须有,fileName显示要下载的附件的名字(action中提供get,set方法) -->
<param name="contentDisposition">attachment;fileName=${fileName}</param>
</result>
action中的代码:
private Sting fileName;
get、set方法
public InputStream getDownloadFile() throws FileNotFoundException{
//此处地址为相对根路径的地址,且要有“/
return ServletActionContext.getServletContext().
getResourceAsStream("/upload/".concat(getFilename()));
}
相关推荐
Struts2文件类型汇总,各种上传文件类型集合。
使用struts2框架进行文件的上传并限制文件的大小与类型,使用struts2框架实现文件下载
Struts2 文件上传下载 多文件 单文件 实例;支持单个或多个文件的上传下载,并且自定义上传文件的大小和类型!!!
Struts2 上传文件 过滤文件类型 过滤大小
STRUTS2学习文档.pdf 对Struts2的一些配置文件进行了详细的说明。 Struts2―表单验证validate(html)对validate的type属性校验类型以及param 做了详细的解释说明。 struts2和struts的比较 让你更清楚的知道struts2...
利用struts2上传文件 环境配置JDK1.8 Eclipse 版本 Version: Mars Release (4.5.0) tomcat版本7.0.40 注意的问题是文件上传的时候的enctype="multipart/form-data" 如果设置错误会报错 今天初次使用Struts 2做文件...
Struts2最新版本2.2.1中所设计的核心库文件,包括以下内容: struts2-core-2.2.1.jar:Struts2框架的核心类库。 xwork-core-2.2.1.jar:Xwork核心类库,Struts2在其上构建。 ognl-3.0.jar:对象图导航语言(Object ...
Struts2属性文件详解 struts.configuration 该属性指定加载Struts 2配置文件的配置文件管理器.该属性的默认值是org.apache.Struts2.config.DefaultConfiguration, 这是Struts 2默认的配置文件管理器.如果需要实现...
Struts2 文件上传之文件类型 allowedTypes,文件类型与allowedTypes的转换
基于struts2的文件上传+过滤器 可以动态的控制文件的类型和文件大小
Struts2 软件下载 Struts2 比较重要的类 操作步骤及框架配置 struts运行机制 2、简单的struts2程序 3、struts2配置文件 4、cion主要内容 Namespace、自定义Action、路径问题、通配符、包含模块配置文件、默认...
用struts2.0实现的文件上传,用myeclipse6.6直接导入便可运行。
、Struts2 主要几句话: 1、Struts2 是由webwork2 发展来的而非Struts1,相比Struts1,Struts2 编码规范跟类似与webwork2 ...8、Struts2 提供了全局范围、包范围和Action 范围的国际化资源文件管理实现
这是一个struts2框架的处理流程的demo,里面有...struts2 result type类型的基本解释图片;相信对于初学者,通过这个demo可以基本掌握struts2的使用,注意,该demo是纯粹的struts2,没有其他框架内容,请注意甄别......
在struts2的返回结果配置中,我们大部分情况使用默认的或者chain或者redirect,其实struts2还有很多其他类型的,今天我们就来看一下都有哪些类型。 打开struts2的源码中struts-default.xml文件,我们能看到如下配置
通过struts2返回json数据类型很好的文档里面有例子说明的
《Struts 2完全学习手册》全面讲述Struts 2开发框架的知识,包括Struts 2中配置文件的详细讲解、国际化与异常处理、数据类型的转换、数据的输入校验、Struts 2强大的标签库、Struts 2中文件的上传与下载、Struts 2对...
熟悉和掌握Struts2自定义类型转换。 熟悉和掌握Struts2内建校验的操作方法 实验环境与设备: 已经接入局域网的网络实验室,机器上装有IE浏览器等; strtus2.5.8 实验内容: (1) 编写一个...
十二、总结 本教程对struts2的基本知识进行了一些说明,关于struts2的更多详细内容应参看struts2的官方文档及提供的app实例。 下面对struts2的基本执行流程作一简要说明,此流程说明可以结合官方提供的struts2结构图...
解决Struts 2配置文件无提示问题 Action名称的搜索顺序 Action配置的各项默认值 result配置的各种视图转发类型 为Action属性注入值 指定Struts 2处理的请求后缀 Struts 2的处理流程与Action的管理方式 为...