javax.faces.DEFAULT_SUFFIX不起作用 [英] javax.faces.DEFAULT_SUFFIX not working

查看:114
本文介绍了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/bar/等时,它应表示您要用作默认文件的物理文件的文件名.只需将其设置为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文件旁边放置一个物理上存在但 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.

如果您在根文件夹中有一个真实的index.xhtml文件并且空的index.jsf文件,则http://localhost:8080/myproject/可以这样工作.

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.

  • JSF Facelets: Sometimes I see the URL is .jsf and sometimes .xhtml. Why?
  • JSF welcome file is not recognized
  • richfaces + index.xhtml having errors

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

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