文件下载中文名称乱码问题

文件下载中文名称乱码问题
文件下载中文名称乱码问题

package com.hs.es.action;

import java.io.File;

import https://www.360docs.net/doc/b010444424.html,mons.io.FileUtils;

import org.apache.struts2.ServletActionContext;

import com.hs.es.GlobalVar.GlobalVar;

import com.hs.es.business.TaskBusiness;

import com.hs.es.filter.AppcontextEvent;

public class FileUpLoad extends ActionClass{

private static final long serialVersionUID = 572146812454l;

/************************************************ 类属性区**************************************************/

private static final int BUFFER_SIZE = 16 * 1024;// 流反冲区大小

private File myFile;// 文件

private String contentType;// 文件类型

private String fileName;// 文件名

private String imageFileName;// 文件最终路径和名称

private String caption;

private Integer userid;// 用户ID

private Integer taskid;// 任务id

// private String fileContentType;//文件类型

// private String fileFileName;//文件名

/**************************************************** get set 方法区*******************************************/

// 特别方法

public void setMyFileContentType(String contentType) {

this.contentType = contentType;

}

// 特别方法

public void setMyFileFileName(String fileName) {

this.fileName = fileName;

}

public File getMyFile() {

return myFile;

}

public void setMyFile(File myFile) {

this.myFile = myFile;

}

public String getImageFileName() {

return imageFileName;

}

public void setImageFileName(String imageFileName) {

this.imageFileName = imageFileName;

}

public String getCaption() {

return caption;

}

public void setCaption(String caption) {

this.caption = caption;

}

public Integer getUserid() {

return userid;

}

public void setUserid(Integer userid) {

https://www.360docs.net/doc/b010444424.html,erid = userid;

}

public Integer getTaskid() {

return taskid;

}

public void setTaskid(Integer taskid) {

this.taskid = taskid;

}

/**************************************************** 业务逻辑方法区******************************************/

/**

* 拷贝文件到另外的位置

*/

// 添加产品文件(后台)

@Override

public String execute() throws Exception {

String separator = System.getProperty("file.separator");//文件分隔符

// System.out.println("上传文件类型:"+contentType);

System.out.println(separator);

if(checkSession() == null)

return LOGIN;

clearErrorsAndMessages(); //????

// ProductpictureBusiness obj = (ProductpictureBusiness) IOC.SellMgr_IOC.get(ProductpictureBusiness.class.getName());

// 定位到项目发布的相对服务器路径Gardens项目名称

String url = ServletActionContext.getRequest().getRequestURL().toString();

System.out.println("url : " + url);

url = url.substring(0,https://www.360docs.net/doc/b010444424.html,stIndexOf("/"))+"/UploadFiles/";

if(AppcontextEvent.getFilepath()==null)

AppcontextEvent.setFilepath(url);//设置文件保存路径到外部文件中去

// 得到项目下webroot 这个路径是在服务器上的

System.out.println(ServletActionContext.getServletContext().getRealPath("/UploadFiles"));

System.out.println(ServletActionContext.getServletContext().getRealPath("/UploadFiles").replace All("/", separator));

File ff = new File(ServletActionContext.getServletContext().getRealPath("/UploadFiles").replaceAll("/", separator));

if (!ff.exists()) {

boolean df = ff.mkdirs(); //创建此抽象路径名指定的目录,包括所有必需但不存在的父目录。

}

String realpath = ff.getAbsolutePath();//返回此抽象路径名的绝对路径名字符串

System.out.println(realpath);

// 如果没有该文件的文件夹则创建一个

if (getUserid() != null) {

String file_path1 = realpath + separator + getUserid() + separator;// userid 文件夹路径

File filepath = new File(file_path1);

if (!filepath.exists()) {

boolean flag = filepath.mkdir();

if (!flag) {

setMessage("设置用户文件夹失败");

return ERROR;

}

}

System.out.println(file_path1);

String file_path2 = null;

if(getTaskid() != null){

file_path2 = file_path1 + getTaskid() + separator; //taskid 文件夹路径

File path = new File(file_path2);

if(!path.exists()){

boolean flag = path.mkdir();

if (!flag) {

setMessage("设置任务文件夹失败");

return ERROR;

}

}

System.out.println(file_path2);

}

// 文件保存路径

System.out.println(fileName);

File thefilepath = new File(file_path2 + fileName);

// 开始移动文件

FileUtils.copyFile(myFile, thefilepath);// copy(myFile, imageFile);

}

TaskBusiness ta = (TaskBusiness)AppcontextEvent.ioc.SellMgr_IOC.get(TaskBusiness.class.getName());

//修改任务是is_finish字段为1

ta.UpdateTaskIs_finish(getTaskid());

// ta.UpdateTasksign(taskid);

return SUCCESS;

}

}

相关主题
相关文档
最新文档