未找到FacesContext

时间:2011-07-27 05:51:11

标签: jsf facescontext

我的jsp页面是: 回到Home.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="f"  uri="http://java.sun.com/jsf/core"%>
<%@ taglib prefix="h"  uri="http://java.sun.com/jsf/html"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<f:view>
    <h:form>
    <center>
        <br><br><br><br>
        <h:outputLink value="EmployeeHome.jsp">Employee Management</h:outputLink><br><br>
        <h:outputLink value="ProjectHome.jsp">Project Management</h:outputLink><br><br>
    </center>
    </h:form>
</f:view>
</body>
</html>

我的web.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>EmployeeMgmt</display-name>
 <welcome-file-list>
    <welcome-file>Home.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/faces/*</url-pattern>
  </servlet-mapping>


</web-app>

我得到的例外:

org.apache.jasper.JasperException: java.lang.RuntimeException: Cannot find FacesContext
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:500)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:428)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

2 个答案:

答案 0 :(得分:5)

<url-pattern>/faces/*</url-pattern>

用于访问JSF页面的URL必须包含上述模式。您可能直接访问JSP。您需要http://host/app/faces/foo.jsp而不是http://host/app/foo.jsp。 URL模式通过提供上下文的JSF servlet路由请求。


<url-pattern>*.faces</url-pattern>

就个人而言,我更喜欢上面的扩展名映射,其中网址变为http://host/app/foo.faces

答案 1 :(得分:3)

我也面临同样的问题。在web.xml中添加

    <welcome-file>faces/Home.jsp</welcome-file>

它对我有用,希望这有帮助。