Download在struts2下的实现
来源:互联网 发布:高性能网络郝卫东 编辑:程序博客网 时间:2024/06/10 07:46
1.jsp页面
<a href="fileDownload?filePath=images/你好啊.txt">点击下载</a>
2.DownloadAction.java
3.struts.xml
4.解决中文乱码的第二种方法
在方法中
HttpServletResponse response=ServletActionContext.getResponse();
fileName=java.net.URLEncoding.encode(fileName,"UTF-8");
response.setHeader("Content-Disposition","attachment;filename="+fileName);
xml中就不用写那条param了
<a href="fileDownload?filePath=images/你好啊.txt">点击下载</a>
2.DownloadAction.java
public Class DownloadAction extends ActionSupport{private String filePath;//文件路径private String fileName;//文件名public InputStream getTargetFile() throws Exception{HttpServletRequest request=ServletActionContext.getRequest();filePath=request.getParameter("filePath");filePath=new String(filePath.getBytes("ISO-8859-0"),"UTF-8");//字节流转化解决后台接受乱码问题fileName=filePath.substring(filePath.lastIndexof("/"));fileName=java.net.URLEncoding.encode(fileName,"UTF-8");//转化乱码解决下载的时候提示文件名乱码问题return ServletActionContext.getServletContext.getResourceAsStream(filePath);}}
3.struts.xml
<action name="fileDownload" class=".."><result name="success" type="stream"><param name="contentType">text/plain</param> //如果是text/plain表示纯文本,text/xml表示xml image/gif image/jepg表示图片<param name="inputName">targetFile</param> //这里取值是去action中的get方法后面的把第一个字符改成小写,如getTargetFile()这里就是targetFile<param name="contentDisposition">attachment;filename="${fileName}"</param>//文件下载的处理方式,一种是inline一种是attachment,inline是内联,默认在浏览器打开,attachment是附件默认的点击保存<param name="bufferSize">4069</param>//设置缓冲</result></action>
4.解决中文乱码的第二种方法
在方法中
HttpServletResponse response=ServletActionContext.getResponse();
fileName=java.net.URLEncoding.encode(fileName,"UTF-8");
response.setHeader("Content-Disposition","attachment;filename="+fileName);
xml中就不用写那条param了
- Download在struts2下的实现
- struts2 download实现
- Download功能的实现
- 在struts2下实现ajax的异步刷新
- Struts2-Download
- struts2下UrlRewriter的实现
- uploadify在struts2下的使用
- Ajax在struts2环境下的使用
- struts2 excel download
- struts2下载download功能
- Ajax利用JQuery在Struts2的实现
- 5.1JEE实习 downLoad 功能的实现
- 关于如何实现在整合struts2和hibernate4框架下对many-to-one级联数据的存储
- 备忘- 在struts2下用urlrewritefilter的问题
- JFreeChart生成柱状图及其在struts2下的展现
- Struts2中配置文件在非默认路径下的加载
- Spring+Struts2+Mybatis在Intellij下的整合
- 基于struts2框架下的验证码实现
- 常见 mysql innodb 表错误
- ubuntu创建用户2
- 第四次随机播放和生日“悖论”NO.3
- WordPress 加载特殊模版文件 以及 扩展用户信息函数
- poj 1273 (nyoj 323) Drainage Ditches : 最大流
- Download在struts2下的实现
- ios 随机数
- 中缀转后缀 c++实现
- NanShan即时通讯之自定义通信协议设计基础
- 谷歌地图纠偏(0.001纠偏)
- annotation与HttpClient(1)--HttpClient简介
- FAT16、FAT32、NTFS和Ext2硬盘分区格式的区别
- Socket TCP协议
- MFC串口通信控件mscomm