个人记录:web导入文件到后台(ie8兼容)

阅读更多
———————————————说明———————————————
返回类型为String,因为ie8的上传调用的js不支持json类型的返回
通过前台处理成json类型
if(d.indexOf(" 
 

————————————————非ie8——————————————-——
引用js


前台


js调用
    $.ajaxFileUpload({
	                url : '/api/nameList/statechange/getMultiInfoExcel',
	                secureuri : false,
	                fileElementId : 'updatePhoneExcel',
	                dataType : "text",
	                //data:dataJson,
	                success : function(d) {
	                	if(d.indexOf(" 
 
后台
@RequiresAuthentication
@RequiresPermissions("Gbs.Extended.Edit")
@RequestMapping(value = "/getMultiInfoExcel", headers = ("content-type=multipart/*"), method = RequestMethod.POST,produces = "text/plain")
public String getMultiInfoExcel(@RequestParam("updatePhoneExcel") MultipartFile file,HttpServletRequest request, HttpServletResponse response
			,HttpSession session) throws IOException{
		Map returnDataMap = new HashMap();
		session.setAttribute("alllist",null);
		List utVOs = new ArrayList();
		if (!file.isEmpty()) {
			String[] allowType = { "xls", "xlsx" };
            String filename = file.getOriginalFilename();
            //解析excel文件,然后进行数据库存取
            //(1)判断文件类型
            if (filename.indexOf(".") == -1)
    			throw new IOException();
    		String type = filename.substring(filename.indexOf(".") + 1);
    		if (type.length() > 4)
    			throw new IOException();
    		Boolean typeFlag = false;
    		for (int i = 0; i < allowType.length; i++)
    		{
    			if (allowType[i].equalsIgnoreCase(type))
    			{
    				typeFlag = true;
    				break;
    			}
    		}
    		if (!typeFlag)
    			throw new IOException();

    		String realPath = "src\\main\\resources\\template\\uploadTemp";
    		String path = realPath+"\\"+filename;
    		File uploadFile = new File(path);
    		FileUtils.copyInputStreamToFile(file.getInputStream(), uploadFile);

			InputStream inStream = new FileInputStream(uploadFile);

			utVOs = readExcelService.readExcelInfo(inStream);

		} else {
			utVOs = null;
		}
		List gbsExtendedVOs = gbsExtendedService.allGbsExtended();
		String notExistEmpIds  = "";
		String notScopeEmpIds  = "";
		if(utVOs!=null){
			for(int i=0;i0){
				notExistEmpIds = notExistEmpIds.substring(0, notExistEmpIds.length()-1);
			}
			if(notScopeEmpIds.length()>0){
				notScopeEmpIds = notScopeEmpIds.substring(0, notScopeEmpIds.length()-1);
			}
			returnDataMap.put("notExistEmpIds", notExistEmpIds);
			returnDataMap.put("notScopeEmpIds", notScopeEmpIds);
			returnDataMap.put("flag", "true");
			return JsonUtil.beanToJson(returnDataMap);
		}
		returnDataMap.put("flag", "false");
		return JsonUtil.beanToJson(returnDataMap);
	}



—————————————————分割线 ie8———————————————————
ie8调用js和css



ie8调用js
        $("#updatePhoneExcel").uploadify({
		        'swf': '/vendors/uploadify/uploadify.swf',
		        'uploader': '/api/nameList/statechange/getMultiInfoExcel',
		        'fileObjName': 'updatePhoneExcel',
		        'buttonText': '请选择文件',
		        'fileTypeExts': '*.xls; *.xlsx',
		        'fileSizeLimit': '10MB',
		        'auto': false,
		        'multi': false,
		        'onUploadSuccess': function (file, data, response) {
		        	if(d.indexOf(" 
 

//函数中调用上一个js
        if(getBrowserVersion()=='MSIE8.0'){
			    	if($("#updatePhoneExcel-queue").html()!=""){
			          	ajaxUrl = '/api/nameList/statechange/getMultiInfoExcel';
			            $("#updatePhoneExcel").uploadify('upload');
			            return;
			        }
			    }

你可能感兴趣的:(java,html,web)