简体   繁体   English

javax.faces.DEFAULT_SUFFIX无效

[英]javax.faces.DEFAULT_SUFFIX not working

Ive been reading some posts about javax.faces.default_suffix but without success when trying to implement it. 我一直在阅读一些关于javax.faces.default_suffix的帖子,但在尝试实现它时没有成功。

Using : jsf 2.0, jboss 7.1, Mojarra 2.1.5 使用:jsf 2.0,jboss 7.1,Mojarra 2.1.5

  • I need to show in URL the following : localhost:8080/myproject/index.jsf 我需要在URL中显示以下内容:localhost:8080 / myproject / index.jsf
  • when navigating also need show the xxx.jsf 导航时还需要显示xxx.jsf

web.xml 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 谢谢

You're mixing the meaning of the default suffix and the URL pattern. 您混合了默认后缀和URL模式的含义。

The javax.faces.DEFAULT_SUFFIX represents the default suffix of the physical file you've in your webapplication which represents a JSF file. javax.faces.DEFAULT_SUFFIX表示您在webapplication中表示JSF文件的物理文件的默认后缀。 This defaults in JSF 2.0 to .xhtml . 这在JSF 2.0中默认为.xhtml If you change it to .jsf , then you should rename all physical files from some.xhtml to some.jsf . 如果将其更改为.jsf ,则应将所有物理文件从some.xhtml重命名为some.jsf This makes generally no utter sense. 这通常没有任何意义。 You should not do that, just get rid of that context param altogether. 你不应该这样做,只是完全摆脱上下文的干扰。

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). <url-pattern>表示最终用户必须在请求URL中使用的默认URL模式,以便调用FacesServlet (而后者又使用默认后缀配置根据URL定位物理文件)。 You said that you want to use *.jsf in URLs, however you have set it to *.xhtml . 您说要在URL中使用*.jsf ,但是您已将其设置为*.xhtml This is not right and changing the default suffix is not the right solution. 这是不对的,更改默认后缀不是正确的解决方案。

You should just set the URL pattern alone, not the default suffix. 您应该只设置URL模式,而不是默认后缀。

<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>

This way http://localhost:8080/myproject/index.jsf will work. 这样http://localhost:8080/myproject/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. 它应该代表物理文件的文件名,当您请求//foo//foo/bar/等文件夹时,您希望将其作为默认文件提供。 Just set it to index.jsf . 只需将其设置为index.jsf

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

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. 但是,您应该记住,容器将在继续请求之前验证物理文件是否存在,以便在缺少请求时可以正确显示404错误。 As *.jsf is actually a virtual URL, that step will fail. 由于*.jsf实际上是一个虚拟URL,该步骤将失败。 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文件来欺骗容器来解决这个问题。

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. 这样http://localhost:8080/myproject/将起作用,前提是您在根文件夹中有一个真正的index.xhtml文件和空的index.jsf文件。

Much easier is to just get rid of virtual URLs and stick to *.xhtml all the time. 更容易就是摆脱虚拟URL并始终坚持使用*.xhtml

See also: 也可以看看:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM