1、后台保存session。
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>
2、request url 中带上sessionid参数
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,
3、后台通过id获取session进行处理。
if(request.getParameter("jsessionid") != null){
session = MySessionContext.getSession(request.getParameter("jsessionid"));
}