1

I have an index.xhtml file, which is the landing page of my application.

I have a logout button which invokes the following method:

public String logout() {
    FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
    return "logout";
}

Which in turns forwards to index.xhtml page from faces-config.xml. However, when I click on logout and reach the index.xhtml page, the page is distorted, without any css or any design.

Where am I getting wrong?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
ItachiUchiha
  • 36,135
  • 10
  • 122
  • 176

1 Answers1

1

The canonical approach is to send a redirect after invalidate of session, otherwise the old session variables are still present in the response of the current request.

Provided that you're using old fashioned JSF navigation cases, just adding

<redirect />

to the navigation case should do.

However, that you got ExternalContext#invalidateSession() to compile means that you're using JSF 2.x. In that case, you can also just utilize its implicit navigation facility without the need for navigation-case boilerplate:

return "/index.xhtml?faces-redirect=true";

If that still doesn't fix your problem, then this is most probably caused by a homegrown servlet filter which overzealously blocks CSS (and JS and image) resources as well when no logged-in user is found. But this problem would not be related to the logout function, you'd already have had the very same problem already when being not logged-in at all.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thanks BalusC, that helps, dunno how i skipped that. Adding to it, can I know why does the back button takes back the user to the dashboard page(page after one logs in), instead of taking him back to index.xhtml – ItachiUchiha May 10 '13 at 16:48
  • @abhinay: that's a different problem. If you have investigated the HTTP traffic in browser's builtin developer toolset, then you'd have noticed that the back button has served the page from browser's cache and not straight from the server. In that case, head to http://stackoverflow.com/a/10305799 – BalusC May 10 '13 at 16:50