Web Flow + JSF集成默认页面

时间:2015-04-07 21:46:37

标签: jsf jsf-2 web.xml spring-webflow spring-webflow-2

我使用Web Flow和JSF,所以它们实际上运行良好。但我试图找出设置默认页面的替代方法与index.html上的重定向不同。

主要问题是网络分析脚本无法正常运行。我无法在首页之前跟踪用户来源。

应用程序在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>

更新:

我将index.html替换为index.jsp,并将响应状态设置为301.至少它适用于Google Analytics,因此我会检查其他分析工具。 但是这个解决方案仍然不能让我满意。

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" );
%>

1 个答案:

答案 0 :(得分:0)

我会使用spring安全项目而不是欢迎文件,因为JSF(或任何视图框架)不知道如何解析welcome-file中的视图,这就是你的逻辑没有执行的原因。

可能的解决方案是使用spring安全项目。将以下内容添加到安全配置

<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="/**" ....

此外,您需要定义一个具有以下定义的无类控制器:(假设您还使用带有Webflow的Spring MVC)

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

我认为在Spring Security配置中定义拦截,转发,路由等等规则并不那么神秘,因为很明显任何此类规则都存储在一个地方。

注意:您可以保留当前的设置并仅使用spring <mvc:view-controller path="/index.jsp" />定义来触发JSF执行。