gpt4 book ai didi

tomcat - 停用 tomcat session

转载 作者:行者123 更新时间:2023-11-28 22:20:31 28 4
gpt4 key购买 nike

我有一个工作项目,我以 tomcat 用户身份登录,但我不知道如何注销,我尝试停用 tomcat session ,我们使用 java spring,这是我尝试从 Controller :

@RequestMapping(value = "/logout", method = RequestMethod.GET)
public ModelAndView logoutAction(HttpSession session, ServletRequest request, ServletResponse response, FilterChain chain) {
logger.info("Start HomeController.logoutAction");
session.invalidate();
request.getSession(true);
logger.info("End HomeController.logoutAction");
return new ModelAndView("home");
}

但是当我在主页中重定向时,我没有提示输入用户名或密码。现在有人知道我该怎么做吗?

最佳答案

我得到了上述问题的答案。我在网上看到了很多答案,但都是一样的。最后从一个人那里我意识到你必须向服务器发送错误的验证数据(用户名和密码),所以那个人写了这个:

function logout(safeLocation){
var mainWindow = window;
invalidateCurentSession();
var outcome, u, m = "You should be logged out now.";
// IE has a simple solution for it - API:
try { outcome = document.execCommand("ClearAuthenticationCache") }catch(e){}
// Other browsers need a larger solution - AJAX call with special user name - 'logout'.
if (!outcome) {
// Let's create an xmlhttp object
outcome = (function(x){
if (x) {
// the reason we use "random" value for password is
// that browsers cache requests. changing
// password effectively behaves like cache-busing.
x.open("HEAD", safeLocation || location.href, true, "logout", "wrongUser");
x.send("");
// x.abort()
return 1;// this is **speculative** "We are done."
} else {
return;
}
})(mainWindow.XMLHttpRequest ? new mainWindow.XMLHttpRequest() : console.log("active"))
}
if (!outcome) {
m = "Your browser is too old or too weird to support log out functionality. Close all windows and restart the browser."
}
window.location = "some url";
return outcome;
}

使用上面的 javascript 函数,创建一个调用此函数的链接(注销):

<a href='javascript:logout()'>logout</a>

或者作为注销页面中的第一个方法。

(附言,对不起,我不记得网址了)

关于tomcat - 停用 tomcat session ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22197442/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com