FacesContext not found



我的jsp页面是:主页.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)
<url-pattern>/faces/*</url-pattern>

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


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

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

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

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

它对我起到了作用,希望这能有所帮助。

相关内容

  • 没有找到相关文章

最新更新