开发者

java.lang.IllegalArgumentException: Illegal view ID in JSF

开发者 https://www.devze.com 2023-03-01 01:59 出处:网络
when i run jsf project in to tomcat it gives me error like below.. java.lang.IllegalArgumentException: Illegal view ID .jsp/Welcome.jsp.The ID must begin with /

when i run jsf project in to tomcat it gives me error like below..

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.Face开发者_运维百科letViewHandler</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>

Welcome.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>


You're telling JSF to use Facelets as view technology, but yet you're actually using JSPs as views. This is not going to work. Facelets is the successor of JSP and you should choose to use the one or the other.

Assuming that you just want to use JSPs, then you should remove the <view-handler> from the faces-config.xml, also remove javax.faces.DEFAULT_SUFFIX param from web.xml and preferably also remove the ConfigureListener declaration from web.xml.

Or if you actually want to use Facelets (recommendable!), then you'll need to configure Facelets and rewrite your JSPs to XHTMLs as per this Facelets developer guide.

0

精彩评论

暂无评论...
验证码 换一张
取 消