2015-02-11 55 views
1

我用我的jsf app.URL沒有改變,我嘗試了漂亮的臉蛋。我按照網站上提到的步驟。
的pom.xml漂亮的臉不起作用

<dependency> 
    <groupId>org.ocpsoft.rewrite</groupId> 
    <artifactId>rewrite-servlet</artifactId> 
    <version>2.0.12.Final</version> 
</dependency> 
<dependency> 
    <groupId>org.ocpsoft.rewrite</groupId> 
    <artifactId>rewrite-config-prettyfaces</artifactId> 
    <version>2.0.12.Final</version> 
</dependency> 

我在WEB-INF添加漂亮-config.xml中/
漂亮-config.xml中

<pretty-config xmlns="http://ocpsoft.org/schema/rewrite-config-prettyfaces" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://ocpsoft.org/schema/rewrite-config-prettyfaces 
         http://ocpsoft.org/xml/ns/prettyfaces/rewrite-config-prettyfaces.xsd"> 

    <url-mapping id="login"> 
     <pattern value="/login" /> 
     <view-id value="/pages/unsecure/login.jsf" /> 
    </url-mapping> 


</pretty-config> 

我的本地項目URL(完整URL)

http://localhost:9080/projectName/pages/unsecure/login.jsf

我使用myfaces2.2.7,spring/security,hibernate,tomcat7
是否有另一個設置我需要做?我失蹤了,我不明白。 ?
正是我應該做什麼在此先感謝..

UPDATE
我沒有得到任何error.just不起作用。 URL不會更改。

回答

3

瀏覽器中的URL不會自動更改。 PrettyFaces將漂亮的URL映射到內部URL。所以,如果你要求:

http://localhost:9080/projectName/login 

你會真正看到/pages/unsecure/login.jsf頁面,在配置中指定。使用JSF導航或內部重定向到此頁面的導航將自動使用漂亮的URL。

如果你想自動從內部URL重定向到從外部請漂亮的URL(如在你的榜樣,),那麼你需要添加一個重寫的條件這樣做:

<pretty-config xmlns="http://ocpsoft.org/schema/rewrite-config-prettyfaces" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://ocpsoft.org/schema/rewrite-config-prettyfaces 
         http://ocpsoft.org/xml/ns/prettyfaces/rewrite-config-prettyfaces.xsd"> 

    <url-mapping id="login"> 
     <pattern value="/login" /> 
     <view-id value="/pages/unsecure/login.jsf" /> 
    </url-mapping> 

    <rewrite match="/pages/unsecure/login.jsf" substitute="/login" redirect="301"/> 

</pretty-config> 

另外,您可以直接使用Rewrite這些規則都(因爲你已經在使用與PrettyFaces擴展重寫),使用Join規則:

@RewriteConfiguration 
public class ExampleConfigurationProvider extends HttpConfigurationProvider 
{ 
    @Override 
    public int priority() 
    { 
    return 10; 
    } 

    @Override 
    public Configuration getConfiguration(final ServletContext context) 
    { 
    return ConfigurationBuilder.begin() 
     .addRule(Join.path("/login").to("/pages/unsecure/login.jsf").withInboundCorrection()); 
    } 
} 

注日e .withInboundCorrection()方法調用。這會自動將舊網址的入站重定向設置爲新網址。

我希望這會有所幫助。乾杯!