2

好吧,当我尝试以这种方式访问​​我的页面时:

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

我得到了错误:

type Status report

message /Odontonew/

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

但是,如果我尝试以这种方式访问​​:

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

这工作正常。所以我确定我的问题出在 web.xml 但我不知道在哪里,请参阅下面我的 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>

在我的项目的根文件夹中,我有页面“index.xhtml”,但我想使用以下路径访问项目:http://XXX.XXX.XXX.XX:8080/Odontonew(没有 index.jon 或 index. html).

4

2 回答 2

3

这是因为您<welcome-file>index.jon</welcome-file>实际上并不存在于根文件夹中。只有一个index.xhtml。当在 URL 中请求文件夹时/,servletcontainer 将首先检查指定的物理文件<welcome-file>是否存在,以便它可以决定是继续请求还是返回 404。此时 servletcontainer 不接受考虑任何已注册 servlet 的映射。在您的特定情况下,index.jon它是一个虚拟 URL,并不代表物理上存在的文件,因此是 404.

您可以通过在同一文件夹中的index.jon文件旁边放置一个空但实际存在的文件来解决此问题。index.xhtml这样你就可以欺骗 servletcontainerindex.jon真正存在,然后它会继续请求,最终将击中FacesServlet谁为index.xhtml.

另一种方法是更改​​ to 的FacesServletURL 模式,*.jon这样*.xhtml您就不需要摆弄虚拟 URL。如果您出于某种不清楚的原因确实需要它*.jon,那么另一种选择是将物理文件从index.xhtmlto重命名index.jon并将javax.faces.DEFAULT_SUFFIX上下文参数设置为.jon.

请注意,具体问题本质上与 JSF 无关。它与基本的servlet有关。当使用不同类型的 servlet 时,您会遇到完全相同的问题。

也可以看看:

于 2013-10-10T14:35:49.860 回答
1

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.

于 2013-10-10T14:50:09.137 回答