var lchs = "close";
window.onunload = function() {
if (lchs == "fresh") {
if (window.screenLeft > 10000) {
logout();
}
} else {
logout();
}
}
window.onbeforeunload = function() {
lchs = "fresh";
}
function logout() {
Ext.Ajax.request({
url : 'servlet/LogoutServlet',
params : {
type : 'Logout'
},
success : function(response, opts) {
var val = Ext.util.JSON.decode(response.responseText);
}
});
}
LogoutServlet'
LogoutServlet:
package com.segsec.gisap.servlet;
import java.io.IOException;
import java.util.HashMap;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.general.Constants;
import com.general.JsonUtil;
import com.segsec.gisap.MainSessionBean;
public class LogoutServlet extends HttpDispatchServlet {
private static final long serialVersionUID = 1L;
public void Logout(HttpServletRequest request,HttpServletResponse response, MainSessionBean session) throws IOException{
/* response.setHeader("Pragma","No-cache");
response.setHeader("Cache-Control","no-cache");
response.setDateHeader("Expires", 0); */
request.removeAttribute("MainSession");
request.getSession().invalidate();
HashMap hm = new HashMap();
hm.put(Constants.NO_SESSION_INFO_KEY, true);
JsonUtil.responseJsonObject(response, hm);
}
}
HttpDispatchServletHttpDispatchServlet:
package com.segsec.gisap.servlet;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import com.general.Constants;
import com.general.JsonUtil;
import com.segsec.gisap.MainSessionBean;
public class HttpDispatchServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private static Logger logger = Logger.getLogger(HttpDispatchServlet.class);
protected Class<?> clazz = this.getClass();
protected Map<String, Method> methods = new HashMap<String, Method>();
protected Class<?> types[] = {HttpServletRequest.class, HttpServletResponse.class, MainSessionBean.class};
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//System.out.println("class:" + clazz.getName() + "\ttype:" + request.getParameter("type"));
Object obj = request.getSession().getAttribute("MainSession");
String ICURURL = null;
if(!MainSessionBean.class.isInstance(obj)){
logger.debug("Error: The main session is null.");
System.out.println("错误:你没有登录系统!");
ICURURL = request.getServerName() + ":" + request.getServerPort() + request.getRequestURI();
System.out.println("请求的Servlet是:"+ICURURL);
Map<String, Object> map = new HashMap<String, Object>();
map.put(Constants.NO_SESSION_INFO_KEY, true);
JsonUtil.responseJsonObject(response, map);
return;
}
MainSessionBean mainSession = (MainSessionBean) obj;
String method= request.getParameter("type");
if(method == null){
logger.info("Error: The parameter(type) is null.");
System.out.println("错误:没有得到要求的method,请检查是否传输了type参数!");
ICURURL = request.getServerName() + ":" + request.getServerPort() + request.getRequestURI();
System.out.println("请求的Servlet是:"+ICURURL);
System.out.println("请求的method是:"+method);
return;
}
Method m = null;
try {
m = this.getMethod(method);
request.setCharacterEncoding("UTF-8");
//response.setCharacterEncoding("UTF-8");
response.setContentType("application/x-json;charset=UTF-8");
m.invoke(this, request, response, mainSession);
}catch (NoSuchMethodException e) {
e.printStackTrace();
logger.info("Error : don`t find the " + method + " method.");
ICURURL = request.getServerName() + ":" + request.getServerPort() + request.getRequestURI();
System.out.println("请求的Servlet是:"+ICURURL);
System.out.println("错误:没有找到" + method + "方法!");
return ;
}catch (Exception e) {
e.printStackTrace();
logger.info("Error : This is error in the " + method + " method.");
ICURURL = request.getServerName() + ":" + request.getServerPort() + request.getRequestURI();
System.out.println("请求的Servlet是:"+ICURURL);
System.out.println("错误:调用" + method + "方法出现错误!");
return;
}
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
this.doGet(request, response);
}
private Method getMethod(String name) throws NoSuchMethodException {
synchronized (methods) {
Method m = (Method)methods.get(name);
if (m == null) {
m = clazz.getMethod(name, types);
methods.put(name, m);
}
return (m);
}
}
}
说明:
上面的代码我是放在一个页面B.html中,LogoutServlet中处理也很简单,就是去清理一下Session。
我在A.html里面有个按钮,window.open('B.html'),在IE中如果反复点击打开B.html然后关闭,这样打开不了几次IE的进程就挂死,IE6、IE7、IE9都有这个问题,IE8没有测试,firefox没有问题。
IE7、IE8、IE9再某个进程卡死后,可以新开选项卡正常打开B.html但原选项卡就没有办法打开了。
不知引起问题的真正原因是什么?反正去掉这段代码就正常了。