0

I try to go to my page "index.xhtml", entering /index.xhtml in browser address bar but it caused 404 error that the index.jsp was not found. I dont have any idea why jsp is called.

My view:

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets" 
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:c="http://java.sun.com/jsp/jstl/core">
       <h:head>
           <title>This is a Test</title>    
       </h:head> 
       <h:body>
           <div>
               <H2>
                   <h:outputText value="test"/>
               </H2>
           </div>
       </h:body>
</html>

My web.xml:

<servlet>
    <servlet-name>FacesServlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>FacesServlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
mehmet cinar
  • 160
  • 1
  • 7
  • Are you really using JSF2? The problem suggests that you're actually using JSF1. It'd be helpful if you elaborate which JARs exactly you placed in classpath, and where you downloaded them from, and which resources you used to learn JSF. – BalusC Jul 24 '13 at 14:58
  • thanks so much it was realy JSF 1 jar. it was old project that i inculed. Therefore what will i have to this topic, delete or approve as answerd ? – mehmet cinar Jul 26 '13 at 14:00
  • I reposted the comment as an answer. – BalusC Jul 26 '13 at 14:15

1 Answers1

1

This suggests that you're actually not using JSF 2.x, but JSF 1.x. In JSF 1.x, the FacesServlet will by default use .jsp suffix to locate the view file based on the request URL. So, when index.xhtml is requested, it will look for the physical file index.jsp. In JSF 2.x the default suffix has changed to .xhtml, which means that when index.xhtml is requested, it will look for the physical file index.xhtml.

The *.xhtml in the <url-pattern> is merely the URL pattern on which the FacesServlet has to listen for on incoming HTTP requests.

In order to properly use JSF 2.x, you should get rid of all JSF 1.x libraries in the runtime classpath. This covers among others the /WEB-INF/lib folder. If you're unsure about the version because it's not mentioned in JAR's filename, extract it using a ZIP tool and look in /META-INF/MANIFEST.MF. Or just delete them all and re-download the right one from http://javaserverfaces.java.net.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • I have same issue even while I'm using JSF 2.x. The reason is I put my resource files at wrong location. When the Servlet can not find the resource file, it fall back to old JSF 1.x suffix pattern ( in this case *.jsf ) – Lê Thọ Dec 02 '17 at 02:52