本文整理汇总了Java中javax.servlet.http.HttpSession.invalidate方法的典型用法代码示例。如果您正苦于以下问题:Java HttpSession.invalidate方法的具体用法?Java HttpSession.invalidate怎么用?Java HttpSession.invalidate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.servlet.http.HttpSession
的用法示例。
在下文中一共展示了HttpSession.invalidate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: clear
import javax.servlet.http.HttpSession; //导入方法依赖的package包/类
@PostMapping("/logout")
public ModelAndView clear(ModelAndView modelAndView, HttpServletRequest request) {
final String hostname = System.getenv().getOrDefault("HOSTNAME", "unknown");
List<Movie> movies = movieDBHelper.getAll();
List<MovieCartItem> movieList = movies.stream()
.map((Movie movie) -> MovieCartItem.builder()
.movie(movie)
.quantity(0)
.total(0)
.build())
.collect(Collectors.toList());
HttpSession session = request.getSession(false);
if (session != null) {
log.info("Invalidating session:{}", session.getId());
session.invalidate();
}
log.info("New Session");
modelAndView.addObject("movies", movieList);
modelAndView.setViewName("home");
modelAndView.addObject("hostname", hostname);
return modelAndView;
}
示例2: doFilter
import javax.servlet.http.HttpSession; //导入方法依赖的package包/类
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) servletRequest;
HttpSession session = request.getSession(true);
Long lastActiveObject = (Long) session.getAttribute(LAST_ACTIVE_SESSION_ATTRIBUTE);
long currentTime = System.currentTimeMillis();
if(lastActiveObject != null) {
long lastActive = lastActiveObject.longValue();
if(currentTime - lastActive > SESSION_TIMEOUT) {
LOG.info(String.format("Invalidated session of %s due to timeout", LogUtil.getUserInfo(request)));
session.invalidate();
session = request.getSession(true);
}
}
session.setAttribute(LAST_ACTIVE_SESSION_ATTRIBUTE, Long.valueOf(currentTime));
filterChain.doFilter(request, servletResponse);
}
示例3: realizarLogout
import javax.servlet.http.HttpSession; //导入方法依赖的package包/类
public String realizarLogout() {
FacesContext context = FacesContext.getCurrentInstance();
HttpSession session = (HttpSession) context.getExternalContext().getSession(false);
session.invalidate();
try {
context.getExternalContext().redirect(context.getExternalContext().getRequestContextPath() + "/index.xhtml");
} catch (IOException e) {
logger.error(e.getMessage());
}
return "webapp/login/login.xhtml?faces-redirect=true";
}
示例4: signOut
import javax.servlet.http.HttpSession; //导入方法依赖的package包/类
@RequestMapping("/logout")
public String signOut(HttpSession session, SessionStatus status, Model model) {
session.removeAttribute("rol");
session.removeAttribute("usuario");
session.invalidate();
status.setComplete();
return "redirect:login?logout";
}
示例5: service
import javax.servlet.http.HttpSession; //导入方法依赖的package包/类
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
final HttpSession sessao = request.getSession(false);
if(sessao != null) {
sessao.invalidate();
}
response.sendRedirect(request.getContextPath());
}
示例6: doFilter
import javax.servlet.http.HttpSession; //导入方法依赖的package包/类
@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) res;
HttpSession session = request.getSession();
String logoutUrl = config.getInitParameter(AuthConst.LOGOUT_URL);
String token = (String) session.getAttribute(AuthConst.TOKEN);
// 主动注销,即子系统提供的注销请求
if ("/logout".equals(request.getRequestURI())) {
// 向认证中心发送注销请求
Map<String, String> params = new HashMap<String, String>();
params.put(AuthConst.LOGOUT_REQUEST, token);
HTTPUtil.post(logoutUrl, params);
// 注销后重定向
response.sendRedirect("/test");
// 注销本地会话
session = SessionStorage.INSTANCE.get(token);
if (session != null) {
session.invalidate();
}
return;
}
// 被动注销,即从认证中心发送的注销请求
token = request.getParameter(AuthConst.LOGOUT_REQUEST);
if (token != null && !"".equals(token)) {
session = SessionStorage.INSTANCE.get(token);
if (session != null) {
session.invalidate();
}
}
chain.doFilter(req, res);
}
示例7: sessionReset
import javax.servlet.http.HttpSession; //导入方法依赖的package包/类
/**
* 重置Session对象
*
* @param request
* @return
*/
public static void sessionReset(HttpSession session) {
// 删除登录用户信息
session.removeAttribute(Const.SESSION_USER);
// 删除登录用户角色权限
// session.removeAttribute(Const.SESSION_ROLE_RIGHTS);
// 删除登录用户功能权限
session.removeAttribute(Const.SESSION_USER_RIGHTS);
// 删除登录用户菜单一览
session.removeAttribute(Const.SESSION_MENU_LIST);
// 销毁session
session.invalidate();
}
示例8: doGet
import javax.servlet.http.HttpSession; //导入方法依赖的package包/类
public void doGet( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException {
/* Récupération et destruction de la session en cours */
HttpSession session = request.getSession();
session.invalidate();
/* Redirection vers le Site du Zéro ! */
response.sendRedirect("./login");
}
示例9: doPost
import javax.servlet.http.HttpSession; //导入方法依赖的package包/类
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
HttpSession session = request.getSession(false);
if (session != null) {
session.invalidate();
}
request.logout();
response.sendRedirect(request.getContextPath() + "/");
}
示例10: invalidateSessions
import javax.servlet.http.HttpSession; //导入方法依赖的package包/类
/**
* Invalidate HttpSessions
*
* @param cn
* Name of the application for which sessions are to be
* invalidated
* @param sessionIds
* @param smClient
* StringManager for the client's locale
* @return number of invalidated sessions
* @throws IOException
*/
protected int invalidateSessions(ContextName cn, String[] sessionIds, StringManager smClient) throws IOException {
if (null == sessionIds) {
return 0;
}
int nbAffectedSessions = 0;
for (int i = 0; i < sessionIds.length; ++i) {
String sessionId = sessionIds[i];
HttpSession session = getSessionForNameAndId(cn, sessionId, smClient).getSession();
if (null == session) {
// Shouldn't happen, but let's play nice...
if (debug >= 1) {
log("WARNING: can't invalidate null session " + sessionId);
}
continue;
}
try {
session.invalidate();
++nbAffectedSessions;
if (debug >= 1) {
log("Invalidating session id " + sessionId);
}
} catch (IllegalStateException ise) {
if (debug >= 1) {
log("Can't invalidate already invalidated session id " + sessionId);
}
}
}
return nbAffectedSessions;
}
示例11: logoutSuccess
import javax.servlet.http.HttpSession; //导入方法依赖的package包/类
@GetMapping(value = "/logoutSuccess")
public String logoutSuccess() {
HttpSession session = SecurityUtil.getSession();
if (session != null) {
session.invalidate();
}
if (SecurityUtil.getCurrUserDetail() != null) {
SecurityContextHolder.clearContext();
}
logger.debug("用户成功退出登录!");
return "login";
}
示例12: doGet
import javax.servlet.http.HttpSession; //导入方法依赖的package包/类
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
HttpSession sessao = request.getSession();
sessao.invalidate();
response.sendRedirect(request.getContextPath() + "/login");
}
示例13: logoutAdmin
import javax.servlet.http.HttpSession; //导入方法依赖的package包/类
@RequestMapping("Admin/LogoutAdmin")
public String logoutAdmin(HttpSession session) {
session.invalidate();
return "redirect:LoginAdmin";
}
示例14: logout
import javax.servlet.http.HttpSession; //导入方法依赖的package包/类
@RequestMapping(value = "/logout", method = GET)
public ModelAndView logout(HttpSession session) {
session.setAttribute("token", null);
session.invalidate();
return new ModelAndView("redirect:/login");
}
示例15: logout
import javax.servlet.http.HttpSession; //导入方法依赖的package包/类
/**
* Logouts a user with the specified request.
*
* @param request
* the specified request
* @param response
* the specified response
* @return {@code true} if succeed, otherwise returns {@code false}
*/
public static boolean logout(final HttpServletRequest request, final HttpServletResponse response) {
final HttpSession session = request.getSession(false);
if (null != session) {
final Cookie cookie = new Cookie("b3log-latke", null);
cookie.setMaxAge(0);
cookie.setPath("/");
response.addCookie(cookie);
session.invalidate();
return true;
}
return false;
}