如何设置 JSF2 <welcome-file>与面孔 servlet 映射? [英] How to set JSF2 <welcome-file> with faces servlet mapping?

查看:19
本文介绍了如何设置 JSF2 <welcome-file>与面孔 servlet 映射?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 Facelets 的简单 JSF2 应用程序.我的 web.xml 设置如下:-

I have a simple JSF2 app using Facelets. My web.xml is set as follows:-

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

我想将应用程序设置为默认欢迎页面,即/pages/login.xhtml.转到浏览器中的上下文根时,我似乎无法获得欢迎文件设置来选择它.

I want to set the app to default to the welcome page which is /pages/login.xhtml. I can't seem to get the welcome-file setting to pick up this when going to the context root in the browser.

我的 web.xml 欢迎设置如下:-

My web.xml welcome setting is as follows:-

<welcome-file-list>
<welcome-file>/pages/login.jsf</welcome-file>
</welcome-file-list>

如何强制欢迎页面转到登录页面并确保它通过faces servlet?

How do I force the welcome-page to goto the login page and ensure it goes through the faces servlet?

如果我使用以下页面显示,但它没有通过faces servlet,因此不会呈现faces 组件:-

If I use the following the page displays but it hasn't gone through the faces servlet and so faces components aren't rendered:-

<welcome-file-list>
<welcome-file>pages/login.xhtml</welcome-file>
</welcome-file-list>

感谢任何帮助!

推荐答案

您必须创建一个空的 login.jsf 文件,与您的 login.xhtml 文件相邻.出于某种原因,需要使用此 hack 来诱使 servlet 容器认为您的欢迎文件存在.

You have to create an empty login.jsf file, adjacent to your login.xhtml file. For some reason this hack is needed to trick the servlet container into thinking your welcome file exists.

注意:所提供的响应仍将是使用您的 login.xhtml 文件的 JSF 响应,而不是您创建的空 login.jsf 文件.

Note: The response served will still be the JSF response using your login.xhtml file, not the empty login.jsf file you create.

这篇关于如何设置 JSF2 &lt;welcome-file&gt;与面孔 servlet 映射?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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