好吧,当我尝试以这种方式访问我的页面时:
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)。
最佳答案
这是因为你的 <welcome-file>index.jon</welcome-file>
造成的实际不存在于根文件夹中。只有一个index.xhtml
。当在类似 /
的 URL 中请求文件夹时,那么 servletcontainer 将首先检查物理文件是否如 <welcome-file>
中指定的那样。存在,以便它可以决定是继续请求还是返回 404。servletcontainer 此时不会考虑任何已注册 servlet 的映射。在您的具体情况下,index.jon
是一个虚拟 URL,并不代表物理上存在的文件,因此是 404。
您可以通过放置一个空的但实际存在的index.jon
来解决这个问题index.xhtml
旁边的文件文件位于同一文件夹中。这样你就欺骗了 servletcontainer index.jon
确实存在,然后它将继续请求,最终将到达 FacesServlet
谁服务于index.xhtml
。
另一种方法是更改 FacesServlet
URL 模式 *.jon
至*.xhtml
这样您就无需摆弄虚拟 URL。如果你真的需要它是 *.jon
由于某些不清楚的原因,另一种选择是将物理文件从 index.xhtml
重命名。至index.jon
并设置javax.faces.DEFAULT_SUFFIX
上下文参数为.jon
.
请注意,具体问题本质上与 JSF 无关。它与基本 servlet 相关。当使用不同类型的 servlet 时,您会遇到完全相同的问题。
另请参阅:
关于Tomcat 找不到作为欢迎文件的 JSF 页面并以 404 结束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19298401/