Question

Well, when i try to access my page in this way:

  http://XXX.XXX.XXX.XX:8080/Odontonew 

I got the error:

type Status report

message /Odontonew/

description The requested resource (/Odontonew/) is not available.

But if i try to acces in this way:

http://XXX.XXX.XXX.XX:8080/Odontonew/index.jon 

This works fine. So i have sure my problem is in web.xml but i don't know where, see bellow my web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 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_3_0.xsd"
    id="WebApp_ID">
    <display-name>Odontonew</display-name>
    <!-- Configuracao do Spring -->
    <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>
  <listener>
    <listener-class>
        org.springframework.web.context.request.RequestContextListener
    </listener-class>
  </listener>
    <!-- Configuracao DO JSF -->
    <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>*.jon</url-pattern>
    </servlet-mapping>

    <!-- Servlet para Direcionar imagens -->
    <servlet>
    <servlet-name>imageServlet</servlet-name>
    <servlet-class>br.com.odontonew.util.ImageServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>imageServlet</servlet-name>
    <url-pattern>/pictures/*</url-pattern>
</servlet-mapping>

    <welcome-file-list>
        <welcome-file>index.jon</welcome-file>
    </welcome-file-list>

    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>

    <context-param>  
    <param-name>primefaces.THEME</param-name>  
    <param-value>afterwork</param-value>  
    </context-param>

    <context-param>   
<param-name>com.sun.faces.writeStateAtFormEnd</param-name>   
<param-value>false</param-value>   
</context-param>

<context-param>
 <param-name>pictureDirectory</param-name>
 <param-value>${user.home}/webapp/Odontonew/pictures/</param-value>
</context-param>

<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
<init-param>
<param-name>thresholdSize</param-name>
<param-value>51200</param-value>
</init-param>
<init-param>
<param-name>uploadDirectory</param-name>
<param-value>${user.home}/webapp/Odontonew/tmp/</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>

</web-app>

In root folder of my project i have the page "index.xhtml", but i wanna access the project with the path: http://XXX.XXX.XXX.XX:8080/Odontonew (without the index.jon or index.html).

Was it helpful?

Solution

It's caused because your <welcome-file>index.jon</welcome-file> does not physically exist in the root folder. There's only an index.xhtml. When a folder is being requested in the URL like /, then the servletcontainer will first check if the physical file as specified in <welcome-file> is present, so that it can decide whether to continue the request or return a 404. The servletcontainer does at that point not take the mappings of any registered servlets into account. In your particular case, index.jon is a virtual URL and does not represent a physically existing file, hence the 404.

You can solve this by placing an empty but physically existing index.jon file next to index.xhtml file in the same folder. This way you fool the servletcontainer that the index.jon really exists and then it will continue the request which will ultimately hit the FacesServlet who serves the index.xhtml.

An alternative is to change the FacesServlet URL pattern of *.jon to *.xhtml so that you never need to fiddle with virtual URLs. If you really need it to be *.jon for some unclear reason, then again another alternative is to rename the physical file from index.xhtml to index.jon and set javax.faces.DEFAULT_SUFFIX context parameter to .jon.

Note that the concrete problem is essentially unrelated to JSF. It's related to basic servlets. You'd have exactly the same problem when using a different kind of servlet.

See also:

OTHER TIPS

As stated in many answers on the topic, welcome file entry represents a physical file path relative to the current URL path ending with /. As you most plausibly don't have any index.jon file in your root directory, you get the error.

So, you can either create a physical file index.jon in you root folder (don't worry, the one rendered will be index.xhtml), or simply switch to *.xhtml URL pattern to get rid of this unnecessary stuff altogether.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top