Navigate to external URL from a backing bean?

前端 未结 2 379
清歌不尽
清歌不尽 2021-01-06 08:12

I\'m trying to implement proper logout for my Java EE / JSF2 application.

It requires two things:

  1. I need to logout from JAAS and invalidate the session
2条回答
  •  情话喂你
    2021-01-06 08:37

    You can also just use ExternalContext#redirect().

    public void logout() throws ServletException, IOException {
        ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
        ((HttpServletRequest) ec.getRequest()).logout();
        ec.invalidateSession();
        ec.redirect("http://example.com/anothercontext/logout");
    }
    

    No need for an intermediating page with a meta refresh.

提交回复
热议问题