当前位置: 首页>>代码示例>>Java>>正文


Java HttpSession.invalidate方法代码示例

本文整理汇总了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;
}
 
开发者ID:redhat-developer-demos,项目名称:popular-movie-store,代码行数:27,代码来源:HomeController.java

示例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);
}
 
开发者ID:kalsowerus,项目名称:Guestbook9001,代码行数:21,代码来源:SessionInvalidationFilter.java

示例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";
}
 
开发者ID:pedrohnog,项目名称:Trabalhos-FIAP,代码行数:16,代码来源:UsuarioMB.java

示例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";
}
 
开发者ID:EventSoftGroup,项目名称:EventSoft,代码行数:10,代码来源:HomeController.java

示例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());
}
 
开发者ID:kashm1r,项目名称:photoiff,代码行数:10,代码来源:Logout.java

示例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);
}
 
开发者ID:sheefee,项目名称:simple-sso,代码行数:36,代码来源:LogoutFilter.java

示例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();
}
 
开发者ID:PekingGo,项目名称:ipayquery,代码行数:19,代码来源:SessionUtil.java

示例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");
}
 
开发者ID:DTAFormation,项目名称:112016.pizzeria-app,代码行数:9,代码来源:DisconnectController.java

示例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() + "/");
}
 
开发者ID:nickscha,项目名称:servlet-auth,代码行数:10,代码来源:MyLogoutServlet.java

示例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;
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:42,代码来源:HTMLManagerServlet.java

示例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";
}
 
开发者ID:DomKing,项目名称:springbootWeb,代码行数:13,代码来源:SecurityController.java

示例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");
}
 
开发者ID:ArtCouSan,项目名称:Projeto_Integrador_3_Semestre,代码行数:7,代码来源:LogoutServlet.java

示例13: logoutAdmin

import javax.servlet.http.HttpSession; //导入方法依赖的package包/类
@RequestMapping("Admin/LogoutAdmin")
public String logoutAdmin(HttpSession session) {
  session.invalidate();
  return "redirect:LoginAdmin";
}
 
开发者ID:iurigodoy,项目名称:Monsters_Portal,代码行数:6,代码来源:LoginAdminController.java

示例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");
}
 
开发者ID:PatternFM,项目名称:tokamak,代码行数:7,代码来源:LoginController.java

示例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;
}
 
开发者ID:daima,项目名称:solo-spring,代码行数:28,代码来源:Sessions.java


注:本文中的javax.servlet.http.HttpSession.invalidate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。