2015-04-07 66 views
0

我使用Web Flow和JSF,因此它們實際上運行良好。但我試圖找出設置默認頁面的另一種方式,不同於在index.html上重定向。Web Flow + JSF集成默認頁面

主要問題是Web分析腳本無法正常工作。我無法跟蹤用戶源主頁。

在Tomcat 8所述的應用程序運行

Web.xml中

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

的index.html

<html> 
    <head> 
     <meta http-equiv="Refresh" content="0; URL=web/home-page"> 
    </head> 
</html> 

UPDATE:

我取代的index.html具有索引。 jsp和我設置響應狀態爲301.至少它適用於谷歌分析,所以我會檢查出其他分析工具。 但是這個解決方案仍然不能滿足我。

的web.xml

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

的index.jsp

<% 
response.setStatus(301); 
String path=(String)request.getAttribute("javax.servlet.forward.request_uri"); 
if(path==null){ 
    path="web/home-page"; 
} 
response.setHeader("Location", path); 
response.setHeader("Connection", "close"); 
%> 
+0

我對Spring Web Flow並不熟悉,但爲什麼不能在'welcome-file'中指定所需的文件呢? – DavidS

+0

感謝您的建議,但不能像JSF那樣使用表達式和其他函數不起作用。它不是簡單的HTML。 – erdoganonur

+0

@erdoganonur您是否在使用彈簧安全項目? – Selwyn

回答

0

我會用Spring Security的項目,而不是歡迎的文件,因爲JSF(或任何視圖框架)不知道如何解決視圖在歡迎文件中,這就是爲什麼你的邏輯沒有執行。

一個可能的解決方案是,如果你正在使用彈簧安全項目。將以下內容添加到您的安全配置中

<security:http auto-config="true" use-expressions="true"> 
<!--- config omitted for brevity --> 
<security:session-management invalid-session-url="/index.jsp"/> 
</security:http> 

這又是一個示例。您還可以使用其他方法來定義規則。這是很模塊化

<security:intercept-url pattern="/**" .... 

此外,你需要用下面的確定指標定義一個沒有階級的控制器:(假設你還使用Spring MVC有一個Webflow)

<mvc:view-controller path="/index.jsp" /> 

我認爲這是不太神祕定義攔截,轉發,路由等等......在Spring Security配置中規則全部清楚,任何這樣的規則都存儲在一個地方。

注意:您可能能夠保留當前的設置並僅使用彈簧<mvc:view-controller path="/index.jsp" />定義來觸發JSF執行。