Web Flow+JSF集成默认页面



我使用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。至少它适用于谷歌分析,所以我会在其他分析工具中查看它。但这个解决方案仍然没有让我满意

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

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

一个可能的解决方案是,如果您正在使用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中使用SpringMVC)

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

我认为在Spring Security配置中定义拦截、转发、路由等规则就不那么神秘了,这样很明显,任何这样的规则都存储在一个地方。

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

最新更新