简体   繁体   English

如何在查看 JSP 页面后注销用户?

[英]How to log user out AFTER viewing JSP page?

I have a scenario whereby I require a user to be logged out after they view a certain page, but not in the same way as a typical logout page.我有一个场景,我要求用户在查看某个页面后注销,但与典型的注销页面不同。

As far as the user can tell, they should still be logged in until they then view a further page.据用户所知,他们应该仍然登录,直到他们查看更多页面。

I cannot figure out a way to do this within the Spring framework other than firing off an Ajax request on the page via JavaScript to /logout.除了通过 JavaScript 向 /logout 发出页面上的 Ajax 请求之外,我无法找到在 Spring 框架中执行此操作的方法。

Scenario: User hits controller -> Return view JSP -> Log user out场景:用户点击控制器 -> 返回视图 JSP -> 注销用户

Wonder if anyone had any ideas, and if I'm missing the obvious?想知道是否有人有任何想法,如果我错过了显而易见的事情?

Thanks谢谢

If the action is based on a frontend behaviour, then you have to implement a front end solution.如果操作基于前端行为,那么您必须实施前端解决方案。

Your first idea looks good to me.你的第一个想法对我来说很好。 When the frontend event is triggered, send an ajax request to call the logout controller.当前端事件被触发时,发送ajax请求调用注销控制器。

If you need to implement a frontend behaviour to show that the user is logout, you can create your own controller call authenticationService.logout();如果您需要实现前端行为来显示用户已注销,您可以创建自己的控制器调用authenticationService.logout(); and send the data needed in JSON.并以 JSON 格式发送所需的数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM