當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。