日期:2014-05-18  浏览次数:20656 次

jspsmartupload 下载中文文档问题,急!
大家好,我使用jspsmartupload实现文件下载。就想网上说的,如果文件名含有中文,下载的时候,中文名会显示为乱码,例如C:\erip\syscat\AIP\shiyong\AIP×ÊÔ´ÊÔÓÃÉêÇë2007-08-23.doc   。然后系统就提示文件找不到。

我按照网上的指示把那两个方法拷贝到jspsmartupload的源码里,然后编译,重新生成jspsmartupload.jar,重新启动tomcat,重新引入到eclipse里,但是现象依旧,请问大家都是这么的吗?谢谢,老板有些着急了,我也不想再换其他的组件!

------解决方案--------------------
String sWjmc= "文件名称 ";//主文件名+扩展名
String sPath=request.getRealPath( "\\ ");//绝对路径
String sLJ=sPath+ "\\ "+sWjmc;
File f = new File(sLJ);
if(f.exists()){
response.setContentType( "application/octet-stream ");
response.setHeader( "Content-disposition ", "attachment; filename= " + new String(sWjmc.getBytes( "gb2312 "), "iso8859-1 "));//防止下载文件名称是中文乱码问题
OutputStream output = null;
FileInputStream fis = null;
try{
output = response.getOutputStream();
fis = new FileInputStream(f);
byte[] b = new byte[1024];
int i = 0;
while((i = fis.read(b)) > 0){
output.write(b, 0, i);
}
output.flush();

}catch(Exception e){
e.printStackTrace();
}
finally{
if(fis != null){
fis.close();
fis = null;
}
if(output != null){
output.close();
output = null;
}
}
session.removeAttribute(new String(sWJMC.getBytes( "gb2312 "), "iso8859-1 "));
}
System.gc();//垃圾回收器


这是我以前写的 希望能对lz有所帮助
------解决方案--------------------
"程序健壮性问题 "
http://community.csdn.net/Expert/topic/5728/5728658.xml?temp=.8024256
建议看下我的问题!
里面有完整的程序.调试通过了.
------解决方案--------------------
看看我用的方法:

public class DownloadServlet extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException{
String filePath = new String(request.getParameter( "file ").trim().getBytes( "8859_1 "), "utf-8 ");
String fileType = request.getParameter( "type ");

File file = new File(filePath);
response.setCharacterEncoding( "gb2312 ");
response.setContentType(fileType);
response.setHeader( "Content-Disposition ", "attachment; filename= " + new String(file.getName().getBytes( "gb2312 "), "iso8859-1 "));
ServletOutputStream out=response.getOutputStream();
BufferedInputStream in=new BufferedInputStream(new FileInputStream(filePath));
byte[] length=new byte[2*1024*1024];
int i=0;
while((i=in.read(length))!=-1){
out.write(length, 0, i);
}
in.close();
out.flush();
out.close();
response.flushBuffer();
}
}
------解决方案--------------------
jspsmartupload可以限制上传和下载文件大小,并不局限于10k。
不过我每次都在上传的时候将名字改掉,饶开中文问题,也防止文件名重复问题。