2010-12-20 60 views
2

我正在嘗試一個簡單的項目來處理jboss,但我堅持這個錯誤(我已經嘗試在URL上使用.jsf)。在Tomcat中工作的應用精細javax.faces.FacesException:java.lang.RuntimeException:找不到FacesContext

javax.servlet.ServletException: java.lang.RuntimeException: Cannot find FacesContext 
javax.faces.webapp.FacesServlet.service 

root cause 

javax.faces.FacesException: java.lang.RuntimeException: Cannot find FacesContext 
org.apache.myfaces.context.servlet.ServletExternalContextImpl.dispatch(ServletExternalContextImpl.java:425) 
org.apache.myfaces.application.jsp.JspViewHandlerImpl.renderView(JspViewHandlerImpl.java:211) 
org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:41) 
org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:132) 
javax.faces.webapp.FacesServlet.service(FacesServlet.java:140) 
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96 

我的web.xml

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" 
     version="2.4"> 
<listener> 
    <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class> 
</listener> 

<servlet> 
    <servlet-name>javax.faces.FacesServlet</servlet-name> 
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> 
    <load-on-startup>1</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
    <servlet-name>javax.faces.FacesServlet</servlet-name> 
    <url-pattern>*.faces</url-pattern> 
    </servlet-mapping> 
    <filter> 
    <filter-name>faces-redirect-filter</filter-name> 
    <filter-class>core.FacesRedirectFilter</filter-class> 
    </filter> 
    <filter-mapping> 
    <filter-name>faces-redirect-filter</filter-name> 
    <url-pattern>*.jsp</url-pattern> 
    </filter-mapping> 

    <welcome-file-list> 
    <welcome-file>index.jsp</welcome-file> 
    <welcome-file>index.html</welcome-file> 
    </welcome-file-list> 
</web-app> 

的面孔,配置XML

<?xml version='1.0' encoding='UTF-8'?> 
<!DOCTYPE faces-config PUBLIC 
"-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN" 
"http://java.sun.com/dtd/web-facesconfig_1_1.dtd">  

<faces-config> 
    <managed-bean> 
    <managed-bean-name>resumeBean</managed-bean-name> 
    <managed-bean-class>core.ResumeBean</managed-bean-class> 
    <managed-bean-scope>session</managed-bean-scope> 
    </managed-bean> 
    <managed-bean> 
    <managed-bean-name>colorBean</managed-bean-name> 
    <managed-bean-class>core.ColorBean</managed-bean-class> 
    <managed-bean-scope>request</managed-bean-scope> 
    </managed-bean> 
    <navigation-rule> 
    <from-view-id>/customize.jsp</from-view-id> 
    <navigation-case> 
     <from-outcome>same-color</from-outcome> 
     <to-view-id>/WEB-INF/results/same-color.jsp</to-view-id> 
    </navigation-case> 
    <navigation-case> 
     <from-outcome>success</from-outcome> 
     <to-view-id>/WEB-INF/results/show-preview.jsp</to-view-id> 
    </navigation-case> 
    </navigation-rule> 
    <navigation-rule> 
    <from-view-id>/customize-bg.jsp</from-view-id> 
    <navigation-case> 
     <from-outcome>success</from-outcome> 
     <to-view-id>/WEB-INF/results/show-preview2.jsp</to-view-id> 
    </navigation-case> 
    </navigation-rule> 
</faces-config> 
+0

沒有足夠的信息。您想要訪問的網址是什麼?你期望它解決的文件的位置/內容是什麼? 從你的過濾器映射看來,你應該訪問以'.faces'結尾的URL以供FacesServlet處理請求(其中包括FacesContext的初始化) – bug 2010-12-20 16:44:12

回答

3

javax.faces.FacesException:了java.lang.RuntimeException:不能找到FacesContext

JSP頁面中的JSF組件抱怨找不到FacesContext。負責創建的人是FacesServlet

這裏,

<servlet-mapping> 
    <servlet-name>javax.faces.FacesServlet</servlet-name> 
    <url-pattern>*.faces</url-pattern> 
</servlet-mapping> 

聲明瞭FacesServlet聽上*.facesurl-pattern。因此,要運行FacesServlet(並創建FacesContext),您需要確保請求URL匹配http://example.com/context/page.faces,因此而不是http://example.com/context/page.jsp

如果您希望使用http://example.com/context/page.jsf,則需要將FacesServleturl-pattern更改爲*.jsf


也就是說,FacesRedirectFilter也是可疑的。是不是它重定向*.jsp*.jsf左右?如果是這樣,那麼您還需要修改該過濾器。然而,如果唯一的目的是爲了防止用戶直接訪問*.jsp文件無FacesServlet參與,那麼下面的安全約束更好地添加到web.xml

<security-constraint> 
    <display-name>Restrict direct access to JSP files</display-name> 
    <web-resource-collection> 
     <web-resource-name>JSP files</web-resource-name> 
     <url-pattern>*.jsp</url-pattern> 
    </web-resource-collection> 
    <auth-constraint /> 
</security-constraint> 

(和刪除Filter)。


無關的問題,你提到的JSF 1.2,但你申報你的faces-config.xml爲JSF 1.1。任何JSF 1.2實現或更新版本都將回退到JSF 1.1兼容性。您還需要將其聲明爲JSF 1.2。

<faces-config version="1.2" 
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:xi="http://www.w3.org/2001/XInclude" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"> 

(和擺脫那DOCTYPE

相關問題