我正在使用ajax加载方法将一些页面内容加载到index.jsp中名为“center_column”的内部div。
$('#center_column').load('abc.jsp', function() { });
但是在加载时我想检查 session 超时并将请求重定向到登录页面。此 session 超时代码位于“abc.jsp”内
我用过
response.sendRedirect("login.html");
它的方法。但这将重新加载 #center_column div 中的 login.html。
但我想将login.html加载到浏览器上,而不是浏览器上的现有页面(index.jsp)。而且我想在不使用 javascript 的情况下解决这个问题。
谁能指导我解决这个问题
谢谢
最佳答案
您必须使用 JavaScript,但它是最少的。尝试像这样在服务器上处理 session 检查:
if (request.getSession(false) == null) {
response.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
然后在客户端的回调函数中,
$('#center_column').load('abc.jsp', function(responseText, textStatus, xhr) {
if (xhr.status == 403)
window.location = '/login.html';
});
关于java - 从页面的内部 div 调用 response.redirect 将新页面加载到浏览器上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14674673/