当上传图片时出现 HTTP ERROR 302 错误, 这是服务端需要登录验证,而客户端uploadify 并没有把 cookie 中的 sessionId 发送给服务器 ,如果有拦截或过滤的话,请求就会被重置,这样就会出现302错误了。
网上有一种解决方法就是在请求后面加上 sessionId (http://fanshuyao.iteye.com/blog/1751684),但好像也不怎么行。现在通过实现HttpSessionListener的sessionCreated和sessionDestroyed 能很好解决问题。
步骤如下:
1、建立自己的SessionContext
/**
* session管理,解决uploadify session丢失问题
* @author lqy
* @date 2013-1-29
*/
public class MySessionContext {
private static MySessionContext instance;
private HashMap<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);
}
}
2、新增一个Session监听类
/**
* Session监听器
* @author lqy
* @date 2013-1-29
*/
public class SessionListener implements HttpSessionListener {
public static Map<String,HttpSession> userMap = new HashMap<String,HttpSession>();
private MySessionContext myc = MySessionContext.getInstance();
public void sessionCreated(HttpSessionEvent httpSessionEvent) {
myc.addSession(httpSessionEvent.getSession());
}
public void sessionDestroyed(HttpSessionEvent httpSessionEvent) {
HttpSession session = httpSessionEvent.getSession();
myc.delSession(session);
}
}
3、在Web.xml中配置监听
<listener>
<listener-class>com.huaxi.expert.web.listener.SessionListener</listener-class>
</listener>
4、在程序中使用
String sid = req.getParameter("sid");
if (sid == null || sid.trim().equals("")) {
res.sendRedirect(req.getContextPath() + "/");
} else {
MySessionContext myc = MySessionContext.getInstance();
HttpSession mySession = myc.getSession(sid);
if(mySession == null){
res.sendRedirect(req.getContextPath() + "/");
}else{
chain.doFilter(request, response);
}
}
获取session
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
蕃薯耀 2013年1月29日 11:17:19 星期二
相关推荐
主要为大家详细介绍了解决jQuery上传插件Uploadify出现Http Error 302错误的方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
uploadify 上传大文件 http 404 错误解决方案
本文给大家介绍jQuery Uploadify 上传插件出现Http Error 302 错误的解决办法,涉及到uploadify上传错误302相关问题,对本文感兴趣的朋友一起看看吧
解决了uploadify插件在chrom频繁崩溃的问题,又遇到了新问题,ff浏览器下报HTTP 302错误, ff浏览器下 uploadify 利用flash进行post上传时没有包含原来的session信息,而是重新创建了一个session,新的session无法...
主要介绍了解决ThinkPHP下使用上传插件Uploadify浏览器firefox报302错误的方法,需要的朋友可以参考下
Uploadify插件的使用,其错误提示不智能,我们可以自定义错误信息,并返回前台显示
[Asp.net]Uploadify上传大文件,Http error 404 解决方案
uploadify的上传方案有两种,一种是flash插件的方式,一种是h5,由于最新的chrome版本总是提示先安装flash插件的问题,而h5又要付费,所以作者吕大豹大牛模仿uploadify写的一个h5的插件叫Huploadify,并且API完全与...
将uploadify的错误提示更改为中文,更改或添加语言文件即可实现自定义的错误提示.
uploadify
解决uploadify上传火狐浏览器下丢失session Flash上传丢失session
主要包括使用的方法,一些主要的属性,一个使用DEMO,还有使用过程中一些问题的解决办法
jquery uploadify插件Demo
NULL 博文链接:https://amandazzu.iteye.com/blog/1428775
Uploadify 参数 Uploadify Version 3.2 Options选项设置
uploadify上传之jsp
uploadify 3.2包.方便大家下载