Navigate to external URL from a backing bean?

前端 未结 2 380
清歌不尽
清歌不尽 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.

    0 讨论(0)
  • 2021-01-06 08:47

    You can create a page logout.xhtml, so the code will look like this:

    public String getLogoutUrl() {
        return "/logout.jsf";
    }
    

    and in the page add:

    <META HTTP-EQUIV="Refresh" CONTENT="0;URL=https://localhost:8080/anotherwebapp/logout.html">
    
    0 讨论(0)
提交回复
热议问题