gpt4 book ai didi

jsf - 未找到 FacesContext

转载 作者:行者123 更新时间:2023-12-01 09:36:27 24 4
gpt4 key购买 nike

我的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>

我得到的异常(exception):

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 模式通过提供上下文的 JSF servlet 路由请求。


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

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

关于jsf - 未找到 FacesContext,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6839934/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com