Tuesday, June 30, 2015

Handling logout mechanism in J2EE way

Last time when I was working with Spring, the logout was handled in such a way:
  <http auto-config="true">

    <logout logout-success-url="/pages/login.xhtml?faces-redirect=true">
But now I'm doing it in pure J2EE way, thus this is what I got:
  <p:commandbutton action="#{myController.logout}" value="logout" />
public class MyController {

 public void logout() throws IOException {
  ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
  ec.redirect(ec.getRequestContextPath() + "/login.xhtml");
Notice the huge difference? With Spring, one statement rules the world.

No comments: