2011-07-27 4 views
3

ma page jsp est: home.jspFacesContext pas trouvé

<%@ 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> 

Mon fichier 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> 

L'exception je suis arrivé:

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) 

Répondre

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

L'URL que vous utilisez pour accéder à la page JSF doit inclure le modèle ci-dessus. Il est probable que vous accédiez directement au JSP. Vous avez besoin de http://host/app/faces/foo.jsp au lieu de http://host/app/foo.jsp. Le modèle d'URL achemine la demande via le servlet JSF qui fournit le contexte.


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

Personnellement, je préfère les correspondances d'extension comme celle-ci où l'URL devient http://host/app/foo.faces

3

je également face à la même question. Ajouter ceci dans web.xml

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

Et cela a fonctionné pour moi, j'espère que cela aide.