richfaces + index.xhtml出现错误 [英] richfaces + index.xhtml having errors

查看:43
本文介绍了richfaces + index.xhtml出现错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法正确加载index.xhtml文件,并且已经检查了所有教程.有人能指出我正确的方向吗?我只浏览了richfaces网站上的教程.

I have been unable to get my index.xhtml file to load properly, and I have checked all the tutorials for this. Can somebody please point me in the right direction? I was only going through the tutorials on the richfaces site.

下面是我的web.xml文件:

Below is my web.xml file:

<?xml version="1.0"?>
<web-app version="2.5" 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-app_2_5.xsd">
<display-name>Greeter</display-name>

<context-param>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>server</param-value>
</context-param>

<context-param>
    <param-name>org.richfaces.SKIN</param-name>
    <param-value>blueSky</param-value>
</context-param>

<context-param>
    <param-name>org.richfaces.CONTROL_SKINNING</param-name>
    <param-value>enable</param-value>
</context-param>

<filter>
    <display-name>RichFaces Filter</display-name>
    <filter-name>richfaces</filter-name>
    <filter-class>org.ajax4jsf.Filter</filter-class>
</filter>

<filter-mapping>
    <filter-name>richfaces</filter-name>
    <servlet-name>Faces Servlet</servlet-name>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>INCLUDE</dispatcher>
</filter-mapping>

<listener>
    <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>

<!-- Faces Servlet -->
<servlet>
    <servlet-name>Loader</servlet-name>
    <servlet-class>com.mounza.common.Loader</servlet-class>
    <load-on-startup>2</load-on-startup>
</servlet>
<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<context-param>
  <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
  <param-value>.xhtml</param-value>
</context-param>

<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.jsf</url-pattern>
</servlet-mapping>

<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/faces/*</url-pattern>
</servlet-mapping>

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

<session-config>
    <session-timeout>
        30
    </session-timeout>
</session-config>

推荐答案

您正在谈论<welcome-file>,对吧?它必须指向一个物理上存在的文件,因为只要请求一个文件夹,servlet容器就内部使用该文件来显示默认资源. servletcontainer将首先检查文件是否存在,然后对此执行转发.如果该文件不存在,您将得到一个404.

You're talking about the <welcome-file>, right? It must point to a physically existing file, because that's internally been used by the servletcontainer to show the default resource whenever a folder is been requested. The servletcontainer will first check if the file exists before performing a forward on this. If the file doesn't exist, you'll just get a 404.

将其与在虚拟URL上执行的JSF结合仅需要一个特殊技巧.基本上,您需要在实际index.xhtml文件旁边的文件夹中,用一个物理上存在但 empty index.jsf的文件来欺骗servlet容器.这样,servletcontainer不会显示404,而是执行对文件的转发,这将自动触发FacesServlet.

Combining this with JSF which get executed on a virtual URL only requires a special trick. You basically need to fool the servletcontainer with a physically existing but empty index.jsf file there in the folder next to your real index.xhtml file. This way the servletcontainer won't show a 404, but perform a forward to the file which will automatically trigger the FacesServlet.

但是,如果您碰巧已经在使用JSF 2.x(似乎并非如此,但是为了完整起见,无论如何,那么您也可以只更改FacesServlet的URL模式) *.jsf(和/faces/*)到*.xhtml.这样,您就不再需要摆弄虚拟URL.在JSF 1.x中这是不可能的,因为FacesServlet会一直在无限循环中调用自身.

But if you happen to already use JSF 2.x (which doesn't seem to be the case, but anyway, just for sake of completeness), then you can also just change the URL pattern of the FacesServlet from *.jsf (and /faces/*) to *.xhtml. This way you do not need to fiddle with virtual URLs anymore. This is not possible in JSF 1.x, because the FacesServlet would keep calling itself in an infinite loop.

这篇关于richfaces + index.xhtml出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆