一、後臺保存session。 java
public class MySessionContext { private static HashMap mymap = new HashMap(); public static synchronized void AddSession(HttpSession session) { if (session != null) { mymap.put(session.getId(), session); } } public static synchronized void DelSession(HttpSession session) { if (session != null) { mymap.remove(session.getId()); } } public static synchronized HttpSession getSession(String session_id) { if (session_id == null) return null; return (HttpSession) mymap.get(session_id); } }
public class MySessionListener implements HttpSessionListener { public void sessionCreated(HttpSessionEvent httpSessionEvent) { MySessionContext.AddSession(httpSessionEvent.getSession()); } public void sessionDestroyed(HttpSessionEvent httpSessionEvent) { HttpSession session = httpSessionEvent.getSession(); MySessionContext.DelSession(session); } }
<listener> <listener-class>com.smarter.filter.MySessionListener</listener-class> </listener>
二、request url 中帶上sessionid參數 session
upload_url : rootPath+"uploadFileAc!upSwf.s", //接收上傳的服務端url flash_url : rootPath+"d/scripts/swfupload/Flash/swfupload.swf",//swfupload壓縮包解壓後swfupload.swf的url button_placeholder_id : "swfu-placeholder1",//上傳按鈕佔位符的id file_types : "*.jpg;*.gif;*.png", file_post_name : "uploadForm.file", post_params:{ "uploadForm.type":"2", "jsessionid":sessionId }, use_query_string : true,
三、後臺經過id獲取session進行處理。 post
if(request.getParameter("jsessionid") != null){ session = MySessionContext.getSession(request.getParameter("jsessionid")); }