2014-03-25 75 views
0

我有一個錯誤頁面映射到404錯誤。它適用於錯誤的路徑和文件擴展名,但不適用於錯誤的JSF資源名稱。JSF:如何在沒有JSTL的情況下重定向到404錯誤頁面?

我的FacesServlet映射到* .jsf。如果我鍵入wrongPageName.jsf,則會得到一個java.lang.ClassNotFoundException:javax.servlet.jsp.jstl.core.Config,因爲MyFaces在這種情況下使用JspViewDeclarationLanguage,它具有對Config的調用。

如果我添加JSTL到我的籌碼我正確地看到錯誤頁面,但我沒有wan't使用JSTL只是,因爲我的MyFaces + JSTL,同時防止我的dev之間的一些不兼容問題團隊使用JSTL而不是使用JSF方式進行操作。

我也測試過與Mojarra同樣的問題。

是否有替代方案?

感謝, 菲利普

堆棧跟蹤:

Grave: Servlet.service() for servlet [facesServlet] in context with path [/colaborador] threw exception [javax/servlet/jsp/jstl/core/Config] with root cause 
java.lang.ClassNotFoundException: javax.servlet.jsp.jstl.core.Config 
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1718) 
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1569) 
    at org.apache.myfaces.view.jsp.JspViewDeclarationLanguage.buildView(JspViewDeclarationLanguage.java:91) 
    at org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:78) 
    at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:267) 
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:198) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) 
    at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) 
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) 
    at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61) 
    at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108) 
    at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137) 
    at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125) 
    at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66) 
    at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449) 
    at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365) 
    at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90) 
    at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83) 
    at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383) 
    at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362) 
    at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) 
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220) 
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) 
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501) 
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170) 
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98) 
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950) 
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) 
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) 
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040) 
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607) 
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:315) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) 
    at java.lang.Thread.run(Thread.java:744) 

回答

1

您可以在web.xml

定義錯誤頁例如

<error-page> 
    <error-code>404</error-code> 
    <location>/faces/error/filenotfound.xhtml</location> 
</error-page> 
<error-page> 
    <exception-type>java.io.FileNotFoundException</exception-type> 
    <location>/faces/error/filenotfound.xhtml</location> 
</error-page> 
0

我能解決這通過設置SUPPORT_JSP_AND_FACES_EL爲false:

<context-param> 
    <param-name>org.apache.myfaces.SUPPORT_JSP_AND_FACES_EL</param-name> 
    <param-value>false</param-value> 
</context-param> 

爲了得到這個工作的設置,你將需要設置EXPRESSION_FACTORY,否則你會得到這樣的:

HTTP Status 500 - No Factories configured for this Application. This happens if the faces-initialization does not work at all - make sure that you properly include all configuration settings necessary for a basic faces application and that all the necessary libs are included. Also check the logging output of your web application and your container for any exceptions! 

,因爲我使用Tomcat,我指定的組織。 apache.el.E​​xpressionFactoryImpl:

<context-param> 
    <param-name>org.apache.myfaces.EXPRESSION_FACTORY</param-name> 
    <param-value>org.apache.el.ExpressionFactoryImpl</param-value> 
</context-param>  
相關問題