struts1.3 下传上载 文件名乱码
struts1.3 上传下载 文件名乱码吸收了很多网上的方案,发现掺合起来才好使。。。。??1. 上传 form传参 a要使用
struts1.3 上传下载 文件名乱码
吸收了很多网上的方案,发现掺合起来才好使。。。。?
?
1. 上传 form传参 a要使用过滤器utf-8 b页面设置成utf-8 c 使用struts1.1以上版本
?
2. 下载 url传参,过滤器居然不好用。把tomcat server.xml URIEncode设成 utf-8传进来的参数终于不是乱码了。
?
但是下载时的名字还是乱码。又在网上查了好多方法 URLEncode 啥的都不好用
?
?
开始设成 String name = new String(uForm.getFileName().getBytes("utf-8"),
"ISO8859_1");?
firefox下载的名字终于对了,ie还是乱码....
?
最后设成 String name = new String(uForm.getFileName().getBytes(""),
"ISO8859_1");
?
最后是这个写的终于通过了?下载时都是正确的中文名字了。
?
贴代码吧~ 没有用到spring action 继承struts的就好了 没必要继承 ActionSupport
?
struts-config.xml
?
?
upload.jsp
?
filelist.jsp
?
?
upload.js
?
?
net.js
?
??
?
?uploadAciton.java
?
?
downlaodAction.java
?
?
listAction.java
?
package com.travelsky.fgos.web.presentation.actions.upload;import java.io.File;import java.text.SimpleDateFormat;import java.util.ArrayList;import java.util.Calendar;import java.util.Date;import java.util.List;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.apache.struts.action.ActionForm;import org.apache.struts.action.ActionForward;import org.apache.struts.action.ActionMapping;import org.springframework.web.struts.ActionSupport;public class ListAction extends ActionSupport {public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response){String path = request.getSession().getServletContext().getRealPath("/file/");try{//getFileInfo(path);request.setAttribute("fileInfoList", getFileInfo(path));}catch(Exception e){return mapping.findForward("failure");}return mapping.findForward("success");}public static List getFileInfo(String path){File file = new File(path); File[] array = file.listFiles();List fileInfoList = new ArrayList();SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");for(int i=0;i<array.length;i++){ List fileInfoItem = new ArrayList(); if(array[i].isFile()){ fileInfoItem.add(array[i].getName()); //0:name Date d = new Date(array[i].lastModified()); fileInfoItem.add(sdf.format(d));//1:time fileInfoItem.add(new Long(array[i].length()/1024));//2:length //fileInfoItem.add(array[i].getPath());//3:path } fileInfoList.add(fileInfoItem); } System.out.print(fileInfoList);return fileInfoList;}}?
?
?
?