javax.faces.FacesException:java.lang.RuntimeException:找不到 FacesContext
我正在尝试一个简单的项目来在 jboss 上工作,但我陷入了这个错误(我已经尝试在 URL 上使用 .jsf
)。 tomcat 中的应用程序工作正常
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>
faces-config 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>
I'm trying a simple project to work on jboss, but I'm stuck at this error (I already tried using .jsf
on the URL). the application in tomcat work's fine
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
my 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>
faces-config 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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
JSP 页面中的 JSF 组件抱怨找不到
FacesContext
。负责创建它的是FacesServlet
。在这里,
您已声明
FacesServlet
来侦听*.faces
的url-pattern
。因此,要运行FacesServlet
(并创建FacesContext
),您需要确保请求 URL 匹配 http://example.com/context/page.faces 因此不是 http://example.com/context/page.jsp。如果您想使用 http://example.com/context/page.jsf,那么您需要将
FacesServlet
的url-pattern
更改为*.jsf
。也就是说,
FacesRedirectFilter
也很可疑。是不是将*.jsp
重定向到*.jsf
之类的?如果是这样,那么您还需要修改该过滤器。但是,如果唯一的目的是阻止用户直接访问*.jsp
文件而不涉及FacesServlet
,那么最好将以下安全约束添加到web。 xml
:(并删除该
过滤器
)。与该问题无关,您提到了 JSF 1.2,但您已将
faces-config.xml
声明为 JSF 1.1。任何 JSF 1.2 实现或更新版本都将回退到 JSF 1.1 兼容性。您还需要将其声明为 JSF 1.2。(并去掉那个
DOCTYPE
)JSF components in the JSP page are complaining that the
FacesContext
cannot be found. The one responsible for creating this is theFacesServlet
.Here,
you've declared the
FacesServlet
to listen on anurl-pattern
of*.faces
. So, to get theFacesServlet
to run (and to create theFacesContext
) you need to ensure that the request URL matches http://example.com/context/page.faces and thus not http://example.com/context/page.jsp.If you rather want to use http://example.com/context/page.jsf, then you need to change the
url-pattern
of theFacesServlet
to*.jsf
.That said, the
FacesRedirectFilter
is suspicious as well. Isn't it redirecting*.jsp
to*.jsf
or so? If so, then you need to modify that filter as well. However, if the sole intent is to prevent users from accessing*.jsp
files directly without involvement ofFacesServlet
, then better add the following security constraint to theweb.xml
:(and remove that
Filter
).Unrelated to the problem, you mentioned JSF 1.2, but you've declared your
faces-config.xml
as JSF 1.1. Any JSF 1.2 implementation or newer will fall back to JSF 1.1 compatibility. You need to declare it as JSF 1.2 as well.(and get rid of that
DOCTYPE
)