IE8下测试通过,测试告诉我在火狐浏览器中出现问题,打断点发现问题
1、不进入springmvc
解决办法是:;jsessionid=<%=sessionId%>
<%
String sessionId = request.getSession().getId();
%>
//上传处理程序url 'uploader' : '${path}/bpmAttachController/fileUpload.do;jsessionid=<%=sessionId%>
2、进入springmvc的controller但是类里面需要调用session,此时后台报空指针异常
解决办法:
import java.util.HashMap; import java.util.Map; import javax.servlet.http.HttpSession; /** * 为解决uploadify在FireFox下上传文件时session丢失而设. * @author fangjian. * */ public class MySessionContext { private static MySessionContext instance; private Map<String, HttpSession> mymap; private MySessionContext() { mymap = new HashMap<String, HttpSession>(); } public static MySessionContext getInstance() { if (instance == null) { instance = new MySessionContext(); } return instance; } public synchronized void AddSession(HttpSession session) { if (session != null) { mymap.put(session.getId(), session); } } public synchronized void DelSession(HttpSession session) { if (session != null) { mymap.remove(session.getId()); } } public synchronized HttpSession getSession(String session_id) { if (session_id == null) return null; return (HttpSession) mymap.get(session_id); } }
修改mvc,在进入页面前加一下一行
//进入页面之前先把session保存到map中
MySessionContext.getInstance().AddSession(request.getSession());
在接收文件上传的方法中得到session,不为空的
HttpSession session = null; String sessionid= (String) request.getParameter("jsessionid"); if (sessionid != null && !"".equals(sessionid)) { session = MySessionContext.getInstance().getSession(sessionid); }
这样就又得到session了,因为页面要传递参数"sessionid"
所以修改jsp的上传处理程序url
<%
String sessionId = request.getSession().getId();
%>
//上传处理程序url
'uploader':'${path}/bpmAttachController/fileUpload.do;jsessionid=<%=sessionId%>?taskId=${taskId}&defId=${defId}&jsessionid=<%=sessionId%>',