您的位置:首页 > 其它

FireFox下面文件上传session丢失情况

2014-10-27 00:00 232 查看
前段时间在做项目的时候用到了JQuery的一个上传插件,但是呢,在火狐下面上传的时候在后台怎么也获取不到一些信息,后来才发现原来是session丢失了,我的解决方案很简单,直接是把要获取的信息加到上传的url后面,然后再从后来截取出来,这样就不会丢失了



这些信息是要传递到后台处理的有用信息,但是session丢失了,用户信息后台获取不到,

通过加载url后面,具体代码如下:

<%@page import="com.sun.corba.se.spi.servicecontext.UEInfoServiceContext,java.util.*"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%
String videoinfo = request.getParameter("video_Info");
List<String> list = (List<String>)request.getSession().getAttribute("videoName");
String userAcc = request.getSession().getAttribute("userAccount").toString();
String userName = request.getSession().getAttribute("userName").toString();
String userOrg = request.getSession().getAttribute("userOrg").toString();
String videoInfo = videoinfo + "~" + userName + "~" + userOrg;//要传递到后台的信息
%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>批量上传界面</title>
</head>
<!-- 验证还是jquery-validation好用,这里省事没用 -->
<body>
<script src="${ctx}/resources/js/jquery-1.8.3.js"></script>
<link rel="stylesheet" type="text/aacss" href="${ctx}/resources/css/uploadify.css" />
<script src="${ctx}/resources/js/jquery.uploadify.js"></script>
<script src="${ctx}/resources/js/jquery.uploadify.min.js"></script>
<style type="text/css">
.loginButton
{
background:#E1E9DC;
width:80px;
height:30px;
border:none;
font-size:13px;
font-family: 微软雅黑;
border-top:1px solid #1C7887;
border-left:1px solid #1C7887;
border-right:1px solid #1C7887;
border-bottom:1px solid #1C7887;
cursor:pointer;
}

.uploadify-button {
width:80px;
height:30px;
border:none;
}
</style>
<script type="text/javascript" >
$(function(){
//alert(window.parent.document.getElementById("add_info").value);
//var uploadify_url = window.parent.document.getElementById("add_info").value;
var uploadify_url = '${ctx}/video/createMoreVideo;jsessionid=<%=request.getSession().getId()%>?videoinfo='+encodeURIComponent('<%=videoInfo%>');//加载后面直接传递

$("#uploadify").uploadify({
"uploader":uploadify_url,
"swf": '${ctx}/resources/js/uploadify.swf',
'script': '',
"buttonClass":"uploadify-button",
"buttonText":"<div class='loginButton'>选择文件</div>",
'width': 79,//buttonImg的大小
'height': 30,//
"folder":"UploadFile", //文件上传路径
"queueID":"fileQueue", //div层的id
"auto":false, //是否立即上传
"progressData":"percentage",
"multi":true , //是否支持多文件上传
"queueSizeLimit":10 ,//最多上传文件个数
"fileSizeLimit":'204800KB', //文件的最大值200M204800KB
"removeTimeout":'2',
"removeCompleted": false,
"fileTypeExts":"*.avi" ,//文件的格式
"fileTypeDesc": "请选择avi格式的文件", //设置文件上传格式显示文字
'onQueueComplete' : function(queueData) {
alert('所有文件上传完成');
window.close();
//$('#myPop2Window').window('close');
},
'onSelect' : function(file) {
//alert('The file ' + file.name + ' was added to the queue.');
if(file.name.split("_").length!=5) {
alert("'"+file.name+"'视频名称格式不正确,如:中国银行_广告_198_1609_中行家庭财产保险游.avi");
$('#uploadify').uploadify('cancel', file.id);
}
if(file.name.split(".").length!=2) {
alert("'"+file.name+"'视频名称格式不正确,如:中国银行_广告_198_1609_中行家庭财产保险游.avi");
$('#uploadify').uploadify('cancel', file.id);
}
<%
for(int i = 0; i < list.size();i++){
String name = list.get(i);
%>
if(file.name=='<%=name%>'){
alert(file.name+"视频已上传过,请重新选择!!");
$('#uploadify').uploadify('cancel', file.id);
}
<%
}
%>
},
"onUploadSuccess": function(file, data, response){
//在每一个文件上传成功或失败之后触发,返回上传的文件对象或返回一个错误,如果你想知道上传是否成功,最后使用onUploadSuccess或onUploadError事件
//alert(data);
},
'onClearQueue' : function(queueItemCount){
alert(queueItemCount + ' file(s) were removed from the queue');
},
"onUploadProgress": function(file,bytesUploaded,bytesTotal,totalBytesUploaded,totalBytesTotal){
$('#pregress').html('总共需要上传'+bytesTotal+'字节,'+'已上传'+totalBytesTotal+'字节')
},
"onCancel" : function(file) {
//alert('The file ' + file.name + ' was cancelled.');
},
'onFallback' : function() {
alert('Flash was not detected.');
}
});

});

</script>
<form id="videoAddForm" method="post" style="text-align: center;background-color: #D7D7D9;width: 100%" enctype ="multipart/form-data">

<table width="100%" border="0px">
<tr>
<td><input type="file" name="uploadify" id="uploadify" /></td>
<td><input class="loginButton" value="提交" type="button" onclick="javascript:$('#uploadify').uploadify('upload','*')" ></td>
<td><input class="loginButton" value="全部清除" type="button" onclick="javascript:$('#uploadify').uploadify('cancel', '*')" ></td>
</tr>
<tr>
<td colspan="4" width="100%" height="100%">
<div id="fileQueue" style="width: 400;height: 350;"></div>
</td>
</tr>
</table>
</form>
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: