1

I have a plain HTML page error.html. When I use

return "error.html?faces-redirect=true";

it will actually redirect to error.xhtml, not error.html.

How can I redirect to a non-JSF page in a JSF action method?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Caau Dung Ngok
  • 109
  • 3
  • 15

1 Answers1

6

The navigation case outcome is treated as a JSF view. So it always expects a JSF view. If renaming error.html to error.xhtml is not possible for some unclear reason (remember, you can safely use plain HTML in a Facelets page), then you'd need to send a redirect to a non-JSF resource yourself using ExternalContext#redirect().

public void someAction() throws IOException {
    // ...

    ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
    ec.redirect(ec.getRequestContextPath() + "/error.html");
}
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555