Struts2文件下载遇到中文乱码、中文丢失的解决方法
来源:互联网 发布:皖南和皖北的差距知乎 编辑:程序博客网 时间:2024/05/01 00:14
当struts下载的时候遇到中文乱码、中文丢失,问题如下:
(1)中文省去的问题,当我的文件是 :海洋视频.mp4,因为前边的是中文,自动省去了。
(2)中文乱码,变成乱码。 --.mp4
(3)变成了 .aciton的名字。
解决方法:
把你的文件名字加上这句话转码一下,就完美解决了。
doFileName = java.net.URLEncoder.encode(doFileName, "UTF-8");
package action;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
public class DownAction {
InputStream inputStream;
String fileName;
public InputStream getInputStream() {
return inputStream;
}
public void setInputStream(InputStream inputStream) {
this.inputStream = inputStream;
}
public String getFileName() throws UnsupportedEncodingException {
return fileName;
}
public void setFileName(String fileName) throws UnsupportedEncodingException {
this.fileName = fileName;
}
public String execute() throws Exception{
File file=new File("D:/image/海洋找不同游戏.mp4"); //手动测试
fileName=file.getName();//获取文件名
System.out.println("刚获取的fileName:"+fileName);
//转换格式
fileName = java.net.URLEncoder.encode(fileName, "UTF-8");
System.out.println("this.getFileName():"+fileName);
try{
inputStream =new FileInputStream(file);
}catch(Exception e){
e.printStackTrace();
}
return "success";
}
}
成功地显示出来了
下载文件的源代码:http://jingyan.baidu.com/album/4853e1e577056a1909f72630.html?picindex=4
下载文件的源代码参考:http://2342615.blog.51cto.com/2332615/716193/
- Struts2文件下载遇到中文乱码、中文丢失的解决方法
- struts2中文乱码解决方法
- Struts2中文乱码解决方法
- Struts2中文乱码解决方法
- struts2中文乱码解决方法
- struts2中文乱码解决方法
- struts2中文乱码解决方法
- Struts2中文乱码解决方法
- struts2中文乱码解决方法
- struts2中文乱码解决方法
- struts2中文乱码解决方法
- STRUTS2 中文乱码解决方法
- struts2中文乱码解决方法
- struts2中文乱码解决方法 .
- struts2中文乱码解决方法
- struts2 中文乱码解决方法
- struts2中文乱码解决方法
- struts2中文乱码解决方法
- 01、Java重这一刻开始
- 设计模式之-单例模式
- Spring Outing
- 研究生的感想
- ionic 部署安卓系统android遇到的坑
- Struts2文件下载遇到中文乱码、中文丢失的解决方法
- Redis的常用命令
- JAVA实现Excel导入/导出(POI)
- Kafka集群搭建
- Zookeeper Windows 安装
- BMP文件格式
- 第二节蓝桥杯第九题 程序设计(满分16分)
- Linux_C笔记day1
- 删除排序二叉树的节点