facebook

MyFaces test.faces is looking for test.jsp

  1. MyEclipse IDE
  2.  > 
  3. Off Topic
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #231901 Reply

    John Brosan
    Member

    Hello all,

    I’m pretty new to J2EE and JSF.

    I am currently using:

    JDK 1.5.0_03
    Eclipse 3.1
    MyEclipse 4.0M2
    JBoss 4.0.2
    MyFaces 1.0.9 (Came with 4.0M2)

    I have created an Enterprise app and have added a few web projects to it. I would like to use MyFaces in the project so I added the JSF capailities to the appropriate web project.

    It looks like the web.xml is looking for files with the extension .faces. I would like to change this to .jsf and I have done so in the web.xml. I then added a new JSP to the project and used the JSF template.

    However, when I attempt to access the JSF page, I get the following 404 message.

    ———————————-
    HTTP Status 404 – /test.jsp

    type Status report

    message /test.jsp

    description The requested resource (/test.jsp) is not available.
    Apache Tomcat/5.5.9
    ——————————–

    What’s strange about this is that the url is as follows:

    http://localhost:8080/TestApp/test.faces

    I don’t understand why test.jsp is being looked for. I’m sure its something that I’ve setup incorrectly, I just don’t know what.

    Here is my web.xml

    
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee   http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
      <context-param>
        <param-name>javax.faces.CONFIG_FILES</param-name>
        <param-value>/WEB-INF/faces-config.xml</param-value>
      </context-param>
      <listener>
        <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
      </listener>
      <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>0</load-on-startup>
      </servlet>
      <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.faces</url-pattern>
      </servlet-mapping>
    </web-app>
    
    

    Here is my faces-config.xml…not sure what should go in here.

    
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE faces-config PUBLIC "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN" "http://java.sun.com/dtd/web-facesconfig_1_1.dtd">
    
    <faces-config />
    
    
    

    Here is the JSF page:

    
    
    <%@ page language="java" pageEncoding="UTF-8"%>
    <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
    <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
    
    <%
    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>My JSF 'test.jsf' starting page</title>
    
        <meta http-equiv="pragma" content="no-cache">
        <meta http-equiv="cache-control" content="no-cache">
        <meta http-equiv="expires" content="0">    
        <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
        <meta http-equiv="description" content="This is my page">
        <!--
        <link rel="stylesheet" type="text/css" href="styles.css">
        -->
    </head>
      
    <body>
        <f:view>
            <f:loadBundle basename="BUNDLE_NAME_HERE" var="bundle"/>
            This is my JSF JSP page. <br>
        </f:view>
    </body>
    </html>
    
    

    Any help that this noob could get would be most appreciated.

    Thanks

    #231939 Reply

    Riyad Kalla
    Member

    Moving to OT > Soft Dev.

    You .jsf is only a page mapping so that your FacesServlet can intercept the call, after that, it needs to resolve to a real resource, in your case a JSP page, so test.jsp is the logical mapping of the “test.jsf” URL, so you will need a backing page by that name. I’m not a JSF expert but there are other fancier ways to map to fancier solutions, but the 1:1 between JSF and JSP is probably a good starting point (with the same names).

    /login.jsf => /login.jsp

    The FacesServlet has a lot of work to do to maintain the component trees, that is why your requests needs to hit the FacesServlet (via the mapping) and not just go directly to the JSP page.

    #232558 Reply

    ttimbul
    Member

    It seems that there is no need to have a file called page.jsf
    Having the mapping for *.jsf files in the web.xml file causes the faces servlet to be invoked and will look for a file with the same prefix (‘page’), but with the ending .jsp instead of .jsf
    This caused me a lot of headaches, but once I figured it out, it wasn’t an issue anymore. So if you want to use faces, then call the file .jsp, but to invoke it, just call the same file with the mapped extension.
    I have no idea how it works for mapped virtual paths.

Viewing 3 posts - 1 through 3 (of 3 total)
Reply To: MyFaces test.faces is looking for test.jsp

You must be logged in to post in the forum log in