java out.write ie8_个人记录:web导入文件到后台(ie8兼容)

正版2册go web编程go语言实战教材

99.9元

包邮

(需用券)

去购买 >

d0b0225ca31099d087c87893ebaa308f.png

———————————————说明———————————————

返回类型为String,因为ie8的上传调用的js不支持json类型的返回

通过前台处理成json类型

if(d.indexOf("

 
 

d = JSON.parse(jQuery(d).text());

}

else{

d = JSON.parse(d);

}

————————————————非ie8——————————————-——

引用js

前台

js调用

$.ajaxFileUpload({

url : '/api/nameList/statechange/getMultiInfoExcel',

secureuri : false,

fileElementId : 'updatePhoneExcel',

dataType : "text",

//data:dataJson,

success : function(d) {

if(d.indexOf("

 
 

d = JSON.parse(jQuery(d).text());

}

else{

d = JSON.parse(d);

}

if(d.flag=="true"){

if(d.notExistEmpIds!=""){

toastr.success("导入模板数据成功!但"+d.notExistEmpIds+"不存在于名册之中");

}else{

if(d.notScopeEmpIds!=""){

toastr.success("导入模板数据成功!但"+d.notScopeEmpIds+"不在您的管理权限范围内");

}else{

toastr.success("导入模板数据成功!");

}

}

self.searchByInfo();

}else{

toastr.error("导入模板数据失败!");

}

},

error : ajaxError,

complete : function() {

$("#showLoading").hideLoading();

}

});

后台

@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;i

boolean existFlag = false;

boolean scopeFlag = false;

for(int j=0;j

if(utVOs.get(i).getEmpID().equals(gbsExtendedVOs.get(j).getEmpID())){

GbsExtendedVO evo = gbsExtendedVOs.get(j);

String str = findDatascopeComtains(getCurrentUserInfo().getDataScope());

if(str.contains(evo.getEmpID()) || str.contains("1039")|| str.contains("1001")){

evo.setTel(utVOs.get(i).getPhone());

gbsExtendedService.updateGbsExtended2(evo);

scopeFlag = true;

}else{

scopeFlag = false;

}

/*DataScopeValidationUtil.validateSingleDatascope(str, "orgUnitID", evo);

evo.setTel(utVOs.get(i).getPhone());

gbsExtendedService.updateGbsExtended2(evo);*/

existFlag = true;

break;

}

}

if(existFlag == false){

notExistEmpIds = notExistEmpIds + utVOs.get(i).getEmpID()+",";

}

if(scopeFlag == false){

notScopeEmpIds = notScopeEmpIds + utVOs.get(i).getEmpID()+",";

}

}

if(notExistEmpIds.length()>0){

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("

 
 

d = JSON.parse(jQuery(d).text());

}

else{

d = JSON.parse(d);

}

if(d.flag=="true"){

if(d.notExistEmpIds!=""){

toastr.success("导入模板数据成功!但"+d.notExistEmpIds+"不存在于名册之中");

}else{

if(d.notScopeEmpIds!=""){

toastr.success("导入模板数据成功!但"+d.notScopeEmpIds+"不在您的管理权限范围内");

}else{

toastr.success("导入模板数据成功!");

}

}

self.searchByInfo();

}else{

toastr.error("导入模板数据失败!");

}

},

'onUploadError': ajaxError,

//加上此句会重写onSelectError方法【需要重写的事件】

'overrideEvents': ['onSelectError', 'onDialogClose'],

//返回一个错误,选择文件的时候触发

'onSelectError': function (file, errorCode, errorMsg) {

switch (errorCode) {

case -110:

toastr.error("文件 [" + file.name + "] 大小超过300K");

break;

case -120:

toastr.error("文件大小异常");

break;

case -130:

toastr.error("文件类型不正确");

break;

}

},

});

//函数中调用上一个js

if(getBrowserVersion()=='MSIE8.0'){

if($("#updatePhoneExcel-queue").html()!=""){

ajaxUrl = '/api/nameList/statechange/getMultiInfoExcel';

$("#updatePhoneExcel").uploadify('upload');

return;

}

}

原文链接:http://labybreath.iteye.com/blog/2400585

java 11官方入门(第8版)教材

79.84元

包邮

(需用券)

去购买 >

f0f3f55624fb396b1764d42d6df88864.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值