javax.faces.DEFAULT_SUFFIX 不工作 [英] javax.faces.DEFAULT_SUFFIX not working

查看:25
本文介绍了javax.faces.DEFAULT_SUFFIX 不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在阅读一些关于 javax.faces.default_suffix 的帖子,但在尝试实现它时没有成功.

Ive been reading some posts about javax.faces.default_suffix but without success when trying to implement it.

使用:jsf 2.0、jboss 7.1、Mojarra 2.1.5

Using : jsf 2.0, jboss 7.1, Mojarra 2.1.5

  • 我需要在 URL 中显示以下内容:localhost:8080/myproject/index.jsf
  • 导航时还需要显示xxx.jsf

web.xml

<welcome-file-list>
    <welcome-file>/comum/inicio/index.xhtml</welcome-file>
</welcome-file-list>

<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>  **have tried *.jsf but with no success**
</servlet-mapping>

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

你能帮我解决这个问题吗?谢谢

Would you help me on this issue please ? thanks

推荐答案

您混淆了默认后缀和 URL 模式的含义.

You're mixing the meaning of the default suffix and the URL pattern.

javax.faces.DEFAULT_SUFFIX 代表您在 Web 应用程序中的 physical 文件的默认后缀,它代表 JSF 文件.这在 JSF 2.0 中默认为 .xhtml.如果将其更改为 .jsf,则应将所有物理文件从 some.xhtml 重命名为 some.jsf.这通常没有完全的意义.你不应该这样做,完全摆脱那个上下文参数.

The javax.faces.DEFAULT_SUFFIX represents the default suffix of the physical file you've in your webapplication which represents a JSF file. This defaults in JSF 2.0 to .xhtml. If you change it to .jsf, then you should rename all physical files from some.xhtml to some.jsf. This makes generally no utter sense. You should not do that, just get rid of that context param altogether.

<url-pattern> 表示最终用户必须在请求 URL 中使用的默认 URL 模式,以便调用 FacesServlet(反过来使用默认后缀配置,根据 URL 定位物理文件).您说要在 URL 中使用 *.jsf,但是您已将其设置为 *.xhtml.这是不对的,更改默认后缀不是正确的解决方案.

The <url-pattern> represents the default URL pattern which the enduser has to use in request URL in order to invoke the FacesServlet (which in turn uses the default suffix configuration to locate the physical file based on the URL). You said that you want to use *.jsf in URLs, however you have set it to *.xhtml. This is not right and changing the default suffix is not the right solution.

您应该只设置 URL 模式,而不是默认后缀.

You should just set the URL pattern alone, not the default suffix.

<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.jsf</url-pattern>
</servlet-mapping>

这样 http://localhost:8080/myproject/index.jsf 就可以了.

还有第三个问题:您完全误解了欢迎文件的用途.它不应该代表主页的路径.它应该代表您希望作为默认文件的物理文件的文件名,当像 //foo//foo/这样的文件夹时条形/ 等被请求.只需将其设置为 index.jsf.

Then there's a third problem: you're completely misunderstanding the purpose of the welcome file. It should not represent the path to the homepage. It should represent the filename of the physical file which you'd like to serve up as default file when a folder like /, /foo/, /foo/bar/, etc is requested. Just set it to index.jsf.

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

但是,您应该记住,容器会在继续请求之前验证物理文件的存在,以便在不存在的情况下正确显示 404 错误.由于 *.jsf 实际上是一个虚拟 URL,因此该步骤将失败.您可以通过在所需的 index.xhtml 文件旁边放置一个物理存在但 empty index.jsf 文件来欺骗容器来解决这个问题文件夹.

However, you should keep in mind that the container will verify the existence of the physical file before continuing the request, so that it can properly show a 404 error if absent. As *.jsf is actually a virtual URL, that step will fail. You can solve that by fooling the container by placing a physically existing but empty index.jsf file next to the index.xhtml file in the desired folder.

这种方式 http://localhost:8080/myproject/ 将起作用,前提是您有一个真正的 index.xhtml 文件和空 index.jsf 根文件夹中的文件.

This way http://localhost:8080/myproject/ will work, provided that you have a real index.xhtml file and empty index.jsf file in the root folder.

更容易的是摆脱虚拟 URL 并始终坚持 *.xhtml.

Much easier is to just get rid of virtual URLs and stick to *.xhtml all the time.

这篇关于javax.faces.DEFAULT_SUFFIX 不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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