本文整理匯總了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;
}