2012-04-09 117 views
0

我有一些问题与JSF显示默认网址:JSF 2.0和欢迎,文件

的URL显示如下:

www.URL.com/PROYECT_NAME/

我希望是这样的

www.URL.com/PROYECT_NAME/home

我送了欢迎文件是这样的。

<welcome-file-list> 
    <welcome-file >faces/views/home.xhtml</welcome-file> 
</welcome-file-list> 

所以我真正想要的是,当JSF表示欢迎文件显示和URL这样www.URL.com/PROYECT_NAME/home或完整路径的面孔/视图/ home.xhtml。

我知道是一个愚蠢的问题,但是我的股票在其

回答

0

这是可能实现使用基于过滤器的servlet等扩展PrettyFaces

它简单易用,具有良好的文档和示例,而是说明你的情况,你可以做这样的事情:

  • 下载prettyfaces.jar并添加到您的类路径中。通常为/WEB-INF/lib文件夹。
  • 将包含URL映射的pretty-config.xml文件添加到/WEB-INF文件夹中。

漂亮-config.xml文件中的示例:

<?xml version="1.0" encoding="UTF-8"?> 
<pretty-config xmlns="http://ocpsoft.com/prettyfaces/3.3.3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://ocpsoft.com/prettyfaces/3.3.3 http://ocpsoft.com/xml/ns/prettyfaces/ocpsoft-pretty-faces-3.3.3.xsd"> 

    <url-mapping id="home"> 
     <pattern value="/home" /> 
     <view-id value="/home.xhtml" /> 
    </url-mapping> 

</pretty-config> 

重定向到这个映射从控制器,你应该使用像pretty: + url-mapping-id的字符串。控制器豆的

实施例:

@ManagedBean 
@ViewScoped 
public class HomeBean 
{ 
    public String goHome() 
    { 
     return "pretty:home"; 
    } 
} 

就是这样。每当您发起请求时,如果PrettyFaces过滤器找到url映射模式/home,它将显示视图ID home.xhtml,但保留URL为/home。漂亮。

此外,作为建议,对于您的welcome-file-list,您只能添加index.html。欢迎的web.xml文件列表标签的

例子:

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

并添加像这样的index.html文件到您的应用程序根目录。 index.html文件的

例子:

 

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
     <head> 
      <title>My Application</title> 
      <meta http-equiv="content-type" content="text/html; charset=utf-8" /> 
      <meta http-equiv="refresh" content="0;url=/myapplication/home" /> 
     </head> 
     <body> 
      <h3>Loading...</h3> 
     </body> 
    </html> 
 

这样,只要有人请求您的应用程序也将得到快速加载页面,将被重定向到/home

我希望它有帮助。