Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 网站建设 > ASP > 在启动程序时得到javax.servlet.ServletException: Cannot find FacesContext,为什么?
【标  题】:在启动程序时得到javax.servlet.ServletException: Cannot find FacesContext,为什么?
【关键字】:javax.servlet.ServletException,Cannot,find,FacesContext
【来  源】:http://blog.csdn.net/mouyong/archive/2007/04/19/1571154.aspx

在启动程序时得到javax.servlet.ServletException: Cannot find FacesContext,为什么?

Your Ad Here

在一般情况下,是因为你直接调用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页面而不是使用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中文技术网上摘过来的。http://hi.baidu.com/jsfcn/blog/item/f684528243a6f2a20cf4d2a6.html

但是据我自己的观察,似乎只有在你写导航规则的时候不写<from-view-id>标记时才会出现Cannot find FacesContext的错误。我不太清楚为什么会这样。只是上网查了之后找到这样一个答案,不知道它们之间又有什么样的联系。

JSP下的彩色验证码的解决:【上一篇】
hiernate 中联合查询,得到的list是一个对象数组,这样需要进行适当处理来取值。:【下一篇】
【相关文章】
  • Cannot forward after response has been committed
  • gvim 出现 cannot register application object 错误信息的解决方法
  • cannot convert parameter 1 from 'class A' to 'class A'
  • Platform Manager cannot create the communication streams needed by the debugger.
  • Hibernate批量查询:Session.find/iterate
  • Linux 文件、内容查找(递归) ,grep ,find
  • 搜索文件的利器_Ava Find
  • Flex Builder 2 cannot locate the required debug version of the Flash Player
  • ORA-02429: cannot drop index used for enforcement
  • PKU1568 Find the Winning Move
  • 【随机文章】
  • login之前的画面设定
  • fedoracore4开机NUMLOCK问题
  • 下一代ADO.NET 8月份社区预览版
  • 图解CACHE不一致性问题[生动透彻]
  • 使用Spring中的Resource接口隔离对文件系统的依赖
  • PSP年代记
  • 光纤的色散(2)
  • [给我一支烟]2z
  • Power over Ethernet工作原理
  • String 与 StringBuffer 的效率比较
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 bbb软讯网络 All Rigths Reserved.