0

I have a JAVA/WEB (JSF) application, when building a new version with Jenkings my system internally sends a message to the user that there is a new version available and that he logout and logsin, however only with this sequence of actions he can't access the update being necessary to close the browser and reopen the page, so how can I kill the tomcat session after the user logout without closing the browser? I've tried several alternatives from trying to kill the session as well as clearing cookies and closing active pages (I've even tried them all together). What can I do?

Here are some attempts I've made but without success:

1. invalidateSession:

FacesContext.getCurrentInstance().getExternalContext().invalidateSession();

2. Clear Cookies:

Cookie[] cookies = ((HttpServletRequest) getExternalContext().getRequest()).getCookies();
        if (cookies != null && cookies.length > 0) {
            for (Cookie cookie : cookies) {
                if (cookie.getName().equals("JSESSIONID")) {
                    cookie.setValue("");
                    cookie.setPath("/");
                    cookie.setMaxAge(0);
                    HttpServletResponse resp = (HttpServletResponse) getExternalContext().getResponse();
                    resp.addCookie(cookie);
                    break;
                }
            }
        }

3. Clear actives views:

Map<String, Object> mapTeste = (Map<String, Object>) FacesContext.getCurrentInstance().getExternalContext().getSessionMap()
                .get("com.sun.faces.application.view.activeViewMaps");

        if (mapTeste != null && !mapTeste.isEmpty() && mapTeste.size() > 1) {
            final Map<String, Object> pp = new HashMap<>();

            mapTeste.entrySet().forEach(entry -> {
                Map<String, Object> mapDentro = (Map<String, Object>) entry.getValue();

                mapDentro.entrySet().forEach(_item -> {
                    pp.put(entry.getKey(), entry.getValue());
                });
            });

            int tt = pp.size();

            for (Map.Entry<String, Object> entryDentro : pp.entrySet()) {
                if (tt > 10) {
                    mapTeste.remove(entryDentro.getKey());
                    tt--;
                }
            }
        }

Enviroment settings:

Netbeans 15;
JDK:15;
TomCat:9.0.33;
Local system: Windows 10 x64
Server: Versão windows server:2012r2
Hérick Raposo
  • 303
  • 2
  • 7
  • 1
    Does this answer your question? [How to invalidate session in JSF 2.0?](https://stackoverflow.com/questions/5619827/how-to-invalidate-session-in-jsf-2-0) – Jasper de Vries Oct 13 '22 at 12:54

0 Answers0