iframe跨域请求 注销
2011年10月10日
a域代码
function mylogout(){
setTimeout(function(){ window.location.href="";},1000);
}
$("#logout").click(function(){
document.domain="hicloud.com";
var remoteHtml=document.getElementById("iframelogout");
remoteHtml.src="";
var doc = remoteHtml.ContentDocument;
mylogout();
});
b域代码
document.domain="hicloud.com";
var url = "";
url = url +"logout";
$.ajax({
type: "GET",
url: url,
dataType: "text"
});
b域过滤器
try
{
//request
req = (HttpServletRequest)request;
//response
resp = (HttpServletResponse)response;
boolean tag = false;
//登录用户
Object object = req.getSession().getAttribute("account");
if (object != null)
{
tag = true;
}
//应用语言
Object lang = req.getSession().getAttribute("lang");
if (lang != null)
{
setLanguage(lang.toString());
}
else
{
setLanguage(req.getLocale());
}
resp.setContentType("text/html;charset=utf-8");
if (tag)
{
filterChain.doFilter(request, response);
}
else
{
//没登录后跳转到action或jsp
// RequestDispatcher rd = req.getRequestDispatcher("/cloud_portal/index.jsp");
resp.sendRedirect("/index.jsp");
// rd.forward(request, response);
}
}
catch (Exception e)
{
logger.error("request url=" + req.getRequestURI(), e);
}
顺便说下 iframe不支持RequestDispatcher 的外部重定向,只支持 resp.sendRedirect内部重定向
2011年10月10日
a域代码
function mylogout(){
setTimeout(function(){ window.location.href="";},1000);
}
$("#logout").click(function(){
document.domain="hicloud.com";
var remoteHtml=document.getElementById("iframelogout");
remoteHtml.src="";
var doc = remoteHtml.ContentDocument;
mylogout();
});
b域代码
document.domain="hicloud.com";
var url = "";
url = url +"logout";
$.ajax({
type: "GET",
url: url,
dataType: "text"
});
b域过滤器
try
{
//request
req = (HttpServletRequest)request;
//response
resp = (HttpServletResponse)response;
boolean tag = false;
//登录用户
Object object = req.getSession().getAttribute("account");
if (object != null)
{
tag = true;
}
//应用语言
Object lang = req.getSession().getAttribute("lang");
if (lang != null)
{
setLanguage(lang.toString());
}
else
{
setLanguage(req.getLocale());
}
resp.setContentType("text/html;charset=utf-8");
if (tag)
{
filterChain.doFilter(request, response);
}
else
{
//没登录后跳转到action或jsp
// RequestDispatcher rd = req.getRequestDispatcher("/cloud_portal/index.jsp");
resp.sendRedirect("/index.jsp");
// rd.forward(request, response);
}
}
catch (Exception e)
{
logger.error("request url=" + req.getRequestURI(), e);
}
顺便说下 iframe不支持RequestDispatcher 的外部重定向,只支持 resp.sendRedirect内部重定向