I created a new project as this tutorial JSF Tools tutorial - Build a JSF 2.0 application
When I try to run it by right clicking on m.xhtml
and selecting run on server, I got a 404 error on m.jsp
.
The URL in browser address bar is :http://localhost:8080/Marwa/m.jsf
The error message says HTTP Status 404 - /Marwa/m.jsp
How is this caused and how can I solve it?
Here is my 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>Marwa</display-name>
<welcome-file-list>
<welcome-file>m.xhtml</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>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>resources.application</param-value>
</context-param>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.ALLOW_JAVASCRIPT</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.PRETTY_HTML</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.DETECT_JAVASCRIPT</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.AUTO_SCROLL</param-name>
<param-value>true</param-value>
</context-param>
</web-app>
It's looking for a JSP file instead of a Facelets file.
JSP was the default view technology in old JSF 1.x. This problem thus suggests that you're actually using JSF 1.x or are running JSF 2.x in JSF 1.x modus.
Make sure that you've really JSF 2.x libraries there. You can check the exact JSF version by reading the server startup log, or by extracting the JSF JAR file with a zip tool and reading MANIFEST file. You can also just re-download the right version at http://myfaces.apache.org/download.html (or http://javaserverfaces.java.net/ for another implementation). Make sure that you get the 2.x version.
Also make sure that faces-config.xml
is declared conform JSF 2.x spec version. It should look like this:
<?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_2_0.xsd"
version="2.0">
<!-- Config here -->
</faces-config>
If your Eclipse didn't do this all automatically, then you're apparently using an outdated Eclipse version. Builtin JSF2 support was introduced in Eclipse Helios (3.6) for Java EE for the first time. You can get the most recent version at http://www.eclipse.org/downloads/ which is currently Indigo SR2 (3.7.2).