gpt4 book ai didi

java.lang.IllegalArgumentException : Illegal view ID in JSF 异常

转载 作者:行者123 更新时间:2023-11-28 22:45:31 24 4
gpt4 key购买 nike

当我在 tomcat 中运行 jsf 项目时,出现如下错误。

java.lang.IllegalArgumentException: Illegal view ID .jsp/Welcome.jsp.  The ID must begin with /
com.sun.faces.application.ViewHandlerImpl.getActionURL(ViewHandlerImpl.java:629)
com.sun.facelets.FaceletViewHandler.getActionURL(FaceletViewHandler.java:781)
com.sun.facelets.FaceletViewHandler.handleFaceletNotFound(FaceletViewHandler.java:686)
com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:637)
com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:106)
com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)

Faces-config.xml

<?xml version='1.0' encoding='UTF-8'?>

<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"
version="1.2">

<application>
<view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
</application></faces-config>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="2.5"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.jsp</param-value>
</context-param>
<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>*.jsf</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>

index.jsp

<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>Index</title>
</head>
<body>
This is my Index page.
<a href="jsp/Welcome.jsf"> <<< here</a>
<br>
</body>
</html>

欢迎.jsp

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>

<html>
<head>
<title>Welcome</title>
</head>
<body>
<f:view>
Welcome Page. <br>
</f:view>
</body>
</html>

最佳答案

您告诉 JSF 使用 Facelets 作为 View 技术,但您实际上正在使用 JSP 作为 View 。这是行不通的。 Facelets 是 JSP 的继承者,您应该选择使用其中之一。

假设您只想使用 JSP,那么您应该删除 <view-handler>来自 faces-config.xml , 也删除 javax.faces.DEFAULT_SUFFIX来自 web.xml 的参数最好还删除 ConfigureListener来自 web.xml 的声明.

或者,如果您实际上想要使用 Facelets(推荐!),那么您将需要配置 Facelets 并将 JSP 重写为 XHTML,按照 Facelets developer guide .

关于java.lang.IllegalArgumentException : Illegal view ID in JSF 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5779208/

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