日期:2014-05-16  浏览次数:20799 次

Ext.ux.UploadDialog上传文件成功后显示“上传失败”及中文文件名乱码问题
从网上找来Ext.ux.UploadDialog上传文件的例子,但是上传文件后页面显示“上传失败”,而且上传中文文件会出现文件名乱码的现象。请各位大侠帮忙解决一下。谢谢了。
HTML code
<html>
<head>
<%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8"%>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<link rel="stylesheet" type="text/css" href="ext-2.2/resources/css/ext-all.css" />
<link rel="stylesheet" type="text/css" href="UploadDialog/css/Ext.ux.UploadDialog.css" />
 <script type="text/javascript" src="ext-2.2/adapter/ext/ext-base.js"></script>
 <script type="text/javascript" src="ext-2.2/ext-all.js"></script
 <script type="text/javascript" src="UploadDialog/Ext.ux.UploadDialog.packed.js"></script>
<script>
Ext.onReady(function() {
    var dialog = new Ext.ux.UploadDialog.Dialog({
        autoCreate: true,
        closable: true,
        collapsible: false,
        draggable: true,
        minWidth: 400,
        minHeight: 200,
        width: 400,
        height: 350,
        permitted_extensions:['JPG','jpg','jpeg','JPEG','GIF','gif','pdf','txt','jar'],   
        proxyDrag: true, 
        resizable: true,
        constraintoviewport: true,
        title: "文件上传",
        url: 'uploadJSPBack.jsp',
        reset_on_hide: false,
        allow_close_on_upload: true
        });
    dialog.show('show-button');
});
</script>
</head>
<body>
</body>
</html>


uploadJSPBack.jsp
HTML code
<%@ page language="java" import="java.util.*,java.io.*,org.apache.commons.fileupload.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>  
    <title>My JSP 'uploadJSPBack.jsp' starting page</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
<%
response.setCharacterEncoding("utf-8");
String uploadPath = "d:\\upload\\";
String tempPath = "d:\\";
try {
         System.out.println("开始进行文件上传");
         DiskFileUpload fu = new DiskFileUpload();
         fu.setSizeMax(4194304); // 设置最大文件尺寸,这里是4MB
         fu.setSizeThreshold(4096); // 设置缓冲区大小,这里是4kb
         fu.setRepositoryPath(tempPath); // 设置临时目录
         List fileItems = fu.parseRequest(request); // 得到所有的文件:
         Iterator i = fileItems.iterator();
         // 依次处理每一个文件:
         while (i.hasNext()) {
            FileItem fi = (FileItem)i.next();
            String fileName = fi.getName();// 获得文件名,这个文件名包括路径:
            System.out.println("name==="+fileName);
            if (fileName != null) {
               // 在这里可以记录用户和文件信息
               // 此处可以定义一个接口(CallBack),用于处理后事。
               // 写入文件a.txt,你也可以从fileName中提取文件名:
               String name = fileName.substring(0,fileName.indexOf("."));
               System.out.println("name==="+name);
               String extfile = fileName.substring(fileName.indexOf("."));
               
               //上传时间作为文件名,用以防止重复上传
               //Timestamp now = new Timestamp((new java.util.Date()).getTime());
               //  SimpleDateFormat   fmt   =   new   SimpleDateFormat("yyyyMMddH