简体   繁体   中英

PrimeFaces Custom Error pages

在我的PrimeFaces项目中,我需要为常规响应错误状态代码(例如401和404)提供一些常规错误页面。有人知道如何解决吗?

It's not handled by JSF, it's handled by the servlet container. You can specify them by <error-page> in web.xml .

<error-page>
    <error-code>401</error-code>
    <location>/errors/401.xhtml</location>
</error-page>
<error-page>
    <error-code>404</error-code>
    <location>/errors/404.xhtml</location>
</error-page>

If you'd like to navigate to them from inside JSF action methods, then you can use ExternalContext#responseSendError() for this.

externalContext.responseSendError(401, "You are not authorized.");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM