单点登录中uploadify上传http请求302重定向异常

   对于单点登录系统,当上传图片和文件时时出现 HTTP ERROR 302 错误, 这是服务端需要登录验证,而客户端uploadify 并没有把cookie中的 sessionId 发送给服务器 ,如果有拦截或过滤的话,请求就会被重置,这样就会出现302错误了。
对于这类问题处理;
  js代码:
  
function getSessionId(){
	var c_name = 'JSESSIONID';
	if(document.cookie.length>0){
		c_start=document.cookie.indexOf(c_name + "=")
		if(c_start!=-1){
			c_start=c_start + c_name.length+1
			c_end=document.cookie.indexOf(";",c_start)
			if(c_end==-1) c_end=document.cookie.length
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
}
    

jquery.uploadify.js文件中uploadify方法:
修改uploader的红色标记部分
'uploader' : '/incms/upload2/init.json ;jsessionid='+getSessionId()
uploader实例代码如下:
$('#uploadXls').uploadify({
		'swf' : SWF,
		'buttonText' : '浏览',
		'width' : 50,
		'height' : 20,
		'fileSizeLimit' : '60MB',
		'multi' : true,
		'auto'  : false,
		'successTimeout':900,//服务器端返回的最大超时时间/秒
		'method' : 'POST',
		'queueSizeLimit' : 100,
		'fileTypeDesc' : 'Upload Files',
		'fileTypeExts' : '*.xls; *.xlsx',
		'formData'     : {'fileAmount':''},//'netType':'',
		'uploadLimit' :15,
		'uploader' : '/incms/upload2/init.json;jsessionid='+getSessionId(),
		'onDialogClose': function(queueData){
			fileAmount = queueData.filesQueued;
		},
		'onDialogOpen':function (){
			$('#uploadXls').uploadify('cancel','*');
		},
		'onUploadStart' : function(file) {
			$.messager.progress({title:'Please waiting',msg:'正在导入.....',text:''});
		},
		'onSelect' : function(file) {
			if(!$("#uploadIsMac").val()){
				$('#uploadXls').uploadify('cancel','*');
				$('#upload_detail_dialog').dialog('close');
				$.messager.alert(titleInfo,"请选择设备");
				return;
			}
		},
		'onCancel': function(file) {
			fileAmount=fileAmount-1;
		},
		'onUploadSuccess' : function(file, data, response) {
			//alert("PP:"+response);
			if(response==false){
				$.messager.progress('close');
				$.messager.alert(titleInfo, '数据太大,请查看是否全部导入成功!');
				$('#uploadXls').uploadify('cancel','*');
				$('#upload_detail_table').datagrid('load');
				$('#upload_detail_dialog').dialog('close');
			}else{
				var json = $.parseJSON(data);
				var jsonData=json.data.msg;//返回信息
				if(jsonData !=null && jsonData !=''){
					if (json.data.code == 3) {
						//选择的对应厂商没有数据
						$.messager.progress('close');
						$('#uploadXls').uploadify('cancel','*');
						$('#upload_detail_table').datagrid('load');
						$('#upload_detail_dialog').dialog('close');
						$.messager.alert(titleInfo, json.data.msg);
					}else if(json.data.code==2){
						//部分导入成功
						$.messager.progress('close');
						$.messager.alert(titleInfo,json.data.offerMsg);
						
						$('#uploadXls').uploadify('cancel','*');
						$('#upload_detail_table').datagrid('load');
						$('#upload_detail_dialog').dialog('close');
					}
				}else{
					 //不显示进度的100%   
					$.messager.progress({title:'Please waiting',msg:'正在导入.....',text:''}); 
				}
			}
		},
		'onAllComplete' : function(event,data) {
		},
		'onUploadError' : function(file, errorCode, errorMsg, errorString) {
        }
	});

猜你喜欢

转载自jiandequn.iteye.com/blog/2381680