百度空间 | 百度首页 
 
查看文章
 
在启动程序时得到javax.servlet.ServletException: Cannot find FacesContext,why?
2006-09-14 09:21

When I launch the application, I get the "javax.servlet.ServletException: Cannot find FacesContext". What does it mean?

在一般情况下,是因为你直接调用JSF页面而不是使用Faces Servlet映射造成的.

 Faces Servlet mapping在web.xml文件中配置,可以被配置为 a suffix mapping or a prefix mapping.

Example of suffix mapping:

    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.jsf</url-pattern>
    </servlet-mapping>

 

Example of prefix mapping:

    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/faces/*</url-pattern>
    </servlet-mapping>

因此, 如果你有一个JSF页面,是位于根目录的 index.jsp 在  suffix mapping的情况下,访问它的URL应该是

 http://hostname/appname/index.jsf 
如果你使用下面的URL:
 http://hostname/appname/index.jsp 
则 "javax.servlet.ServletException: Cannot find FacesContext" exception 会出现.

在 prefix mapping的情况下,URL应该是 :

 http://hostname/appname/faces/index.jsp 

 

为了避免该问题,你可以把你的index.jsp该为home.jsp, 而把index.jsp的内容改为 :

<html>
 <head></head>
<body>
 <jsp:forward page="home.jsf" />
</body>
</html>

上面的示例是使用  *.jsf 后缀mapping.

 


类别:jsf - faq | 添加到搜藏 | 浏览() | 评论 (6)
最近读者:
 
网友评论:
1
2006-12-30 10:09 | 回复
言简意赅
 
2
2007-04-19 18:37 | 回复
但是据我自己的观察,似乎只有在你写导航规则的时候不写标记时才会出现Cannot find FacesContext的错误。我不太清楚为什么会这样。
 
3
2007-07-07 19:24 | 回复
规范化
 
4
2007-11-03 16:06 | 回复
不明白呢! 解决方案没?????
 
5
2007-12-13 09:42 | 回复
这么说我就不能像纯jsp那样,访问一个目录会出现当前所有文件的列表?
 
6
2008-07-18 17:48 | 回复
晕,我的配置没错。但是也报这个错。tomcat 报 严重: Servlet.service() for servlet jsp threw exception java.lang.RuntimeException: Cannot find FacesContext at javax.faces.webapp.UIComponentClassicTagBase.getFacesContext(UIComponentClassicTagBase.java:1797) at javax.faces.webapp.UIComponentClassicTagBase.setJspId(UIComponentClassicTagBase.java:1614)........ 前台报: java.lang.UnsupportedOperationException javax.faces.context.FacesContext.getELContext(FacesContext.java:137)........ 可否给个提示?
 
发表评论:
姓 名:
网址或邮箱: (选填)
内 容:
验证码: 请点击后输入四位验证码,字母不区分大小写
      

     
 
精彩相册
   
     

©2009 Baidu