首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

JQuery上传插件Uploadify浏览器支持有关问题(大神帮帮忙)

2013-04-20 
JQuery上传插件Uploadify浏览器支持问题(大神帮帮忙)JQuery上传插件Uploadify 浏览器问题:WIN7 系统+ IE8

JQuery上传插件Uploadify浏览器支持问题(大神帮帮忙)
JQuery上传插件Uploadify 浏览器问题:
WIN7 系统  + IE8 上传正常。
WINDOWSXP 系统 +IE8 上传不了,问题调试发现 action 中的 upload 方法中

Map<String, MultipartFile> fileMap  没有值,不知道为什么。

但是   WIN7 系统  + IE8     或者 WINXP+谷歌浏览器 都是有值的。
有哪位大哥大姐大仙们遇到过这样的问题吗,救救我吧!!!!


JS方法
function uploadify(){
$("#file_upload").uploadify({
'method'        : 'post',
        'height'        : 27,
        'width'         : 80,
        'buttonText'    : '添加附件...',  
        'swf'           : getRootPath()+'/AircrewHealth/resources/js/uploadify/uploadify.swf?ver=' + Math.random(),  
        'uploader'      : getRootPath()+'/AircrewHealth/upload.do;jsessionid='+$("#sessionUID").val()+'?method=upload&jsessionid=' + $("#sessionUID").val(),  
        'auto'          : false,
        'fileSizeLimit' : '30720KB',
        'fileTypeExts'  : '*.doc;*.docx; *.jpg; *.rar;*.html;*htm;*.xls;*.xlsx;',
        'cancelImg' :  getRootPath()+'/AircrewHealth/resources/js/uploadify/uploadify-cancel.png',
        'uploadLimit' : 3,
        'onUploadStart' : function(file) {
        },  
        'onUploadSuccess':function(file,data, response){
        alert('上传文件: ' + file.name + '\n上传状态: ' + response + '\n上传服务器路径:' + data);
        //alert('The file ' + file.name + ' was successfully uploaded with a response of ' + response + ':' + data);
         $("#tempFileName").val(file.name);
         $("#"+idName).val(data);
        },
        'onUploadComplete':function(){  
            // $('#importLispDialog').window('close');  
         }  
    });
}



ACTION 方法

@SuppressWarnings("unused")
@RequestMapping(params = "method=upload", method = RequestMethod.POST)
public @ResponseBody String upload(HttpServletRequest request, HttpServletResponse response) {
//request = new MulpartRequestWrapper(request);

String responseStr="";  
    MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;    


    //获取前台传值  
    String[] userNames = multipartRequest.getParameterValues("userName");  
    String[] contents = multipartRequest.getParameterValues("content");  
    String userName="";  
    String content="";  
    if(userNames!=null){  
        userName=userNames[0];  
    }  
    if(contents!=null){  
        content=contents[0];  
    }  
        Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();  
        MultipartFile file11 = multipartRequest.getFile("Filename");
        //String ctxPath = request.getSession().getServletContext().getRealPath("/")+ "\" + "images\";    
        //String ctxPath=request.getSession().getServletContext().getRealPath("/")+"uploads\"; 
        String ctxPath= HNAServletContextListener.getSYS_UPLOADPATH_PATH();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM");  
    String ymd = sdf.format(new Date());  
    ctxPath += ymd + "/";  
    //创建文件夹  
        File file = new File(ctxPath);    
        if (!file.exists()) {    
            file.mkdirs();    
        }    
        String fileName = null;
        String path=null;
        for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {    
            // 上传文件名    
            // System.out.println("key: " + entity.getKey());    
            MultipartFile mf = entity.getValue();    
            fileName = mf.getOriginalFilename();  
           //String fileExt = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();      
           //SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");  
           // String newFileName = df.format(new Date()) + "_" + new Random().nextInt(1000) + "." + fileExt;  
            
            String strEnc = DesEncrypt.aircrewhealthGetEncString(fileName);// 加密字符串,返回String的密文


String uuid = UUID.randomUUID().toString().replaceAll("\\-", "");// 返回一个随机UUID。
String suffix = fileName.indexOf(".") != -1 ? fileName.substring(fileName.lastIndexOf("."), fileName.length()) : null;

String newFileName = strEnc + "-" + uuid + (suffix!=null?suffix:"");// 构成新文件名。

            
            File uploadFile = new File(ctxPath + newFileName);    
            try {  
                FileCopyUtils.copy(mf.getBytes(), uploadFile); 
                path =ctxPath+newFileName;
            responseStr="上传成功";  
        } catch (IOException e) {  
            responseStr="上传失败";  
            e.printStackTrace();  
        }    
        }   
       
        return path;  
} JQuery?Uploadify?浏览器
[解决办法]
既然在别的系统下能用,说明代码没有问题,那应该就是系统兼容性的问题。jquery是什么版本的。下载个最新的看下呢
[解决办法]
springmvc?
改成这样试试

@RequestMapping(value="/upload.do", method = RequestMethod.POST)
public String handleUploadData(String name,@RequestParam("file") CommonsMultipartFile file){
if (!file.isEmpty()) {
   String path = this.servletContext.getRealPath("/tmp/");  //获取本地存储路径
   System.out.println(path);
   String fileName = file.getOriginalFilename();
   String fileType = fileName.substring(fileName.lastIndexOf("."));
   System.out.println(fileType); 
   File file2 = new File(path,new Date().getTime() + fileType); //新建一个文件
   try {
    file.getFileItem().write(file2); //将上传的文件写入新建的文件中
   } catch (Exception e) {
    e.printStackTrace();
   }
   return "upload-ok";
}else{
return "upload-error";
}
}

热点排行