开发者

handling exception messages in jsf

i have a servlet filter which controls if my web application is started normally;

public void doFilter(ServletRequest aReq, ServletResponse aResponse, FilterChain aChain) throws IOException, 开发者_开发问答ServletException
    {
        HttpServletRequest request = (HttpServletRequest) aReq;
        HttpServletResponse response = (HttpServletResponse) aResponse;


        if(!myContext.isSystemReady())
        {
            // SHOW AN ERROR PAGE WITH SOME EXCEPTION MESSAGE
        }

        aChain.doFilter(request, aResponse);
        return;

    }

what is the best way to show error messages in this style?

  • if i use

    request.setAttribute("errMsj", "System not ready. Contact your web administrator");

how can i show it in my jsf page?

ERROR !<br />
detailed message is: <h:outputText value="errMsj HERE!"></h:outputText>
  • or should i use a ststusbean to show error messages? in this time i should access facescontext in filter and write error msg to that bean. may there be a problem with it?

  • or any better ideas?

(using jsf2.0)


You can redirect to a specific error page by defining a web-app/error-page element in your web.xml:

<error-page>
  <error-code>500</error-code>
  <location>/error.xhtml</location>
</error-page>

Check the schema, there are more features (like reacting to specific exception classes).

Me peronally, I'd just throw an exception in doFilter (having full exception stack trace may be critical). The exception can later on be retrieved as #{requestScope['javax.servlet.error.exception']} if you want error page to be JSF page.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜