当会话过期时,我使用spring过滤器重定向到登录页面。它在页面刷新调用中工作得很好,但我的应用程序中有一个上载选项,这是一个ajax调用。当用户点击upload按钮时,一旦会话到期,它不会重定向到登录页面。为什么会这样呢?
请提供您宝贵的建议
提前感谢
发布于 2014-10-14 17:58:27
如果你使用ajax,那么我认为页面不会重定向,因为你正在进行部分调用。更好的方法是,当ajax调用没有返回所需的值,并且会话似乎过期时,只使用javascript部分刷新页面。下面是代码
location.reload();
发布于 2014-10-14 18:20:21
在Java script中
//Add here Your Ajax call
//post ajax call
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
var res=xmlhttp.responseText;
if(var==1) //checking if response is 1. I'll return 1 if session expires else whatever data makes sense
{
location.reload();
}
else
{
// do stuff you'll do if session exists
}
}
}
在Java部件中
if(request.getSession()==null)
{
response.getOutputStream().print("1");
}
else
{
//do required stuffs
}
https://stackoverflow.com/questions/26357584
复制相似问题