Spring Webflow 2 和可收藏的 URL

标签 spring seo friendly-url deep-linking spring-webflow-2

目前由于 Post/Redirect/Get 模式,所有流 url 都类似于 <site_url>/flow_name?execution=?并且不保留输入的 GET 参数。因此用户无法复制 url 或将其添加为书签。

有什么建议可以巧妙地完成吗?

最佳答案

我们可以通过自定义 SWF API 的 FlowHandlerAdapter 为基于 SWF 的应用程序的 URL 添加书签。

这是一个示例:

我的 SWF 配置文件应该有:

<bean id="flowController" class="org.springframework.webflow.mvc.servlet.FlowController">
      <property name="flowHandlerAdapter" ref="customFlowHandlerAdapter" /> 
     </bean>

     <bean id="customFlowHandlerAdapter" class="com.xyz.CustomFlowHandlerAdapter">
        <property name="flowExecutor" ref="flowExecutor" /> 
        <property name="flowUrlHandler" >
            <bean class="com.xyz.CustomURLFlowHandler" /> 
        </property>
     </bean>

我的 CustomFlowHandlerAdapter 将具有:

public class CustomFlowHandlerAdapter extends FlowHandlerAdapter {

...

@Override
    public ModelAndView handle(HttpServletRequest request,
            HttpServletResponse response, Object handler) throws Exception {
        FlowHandler flowHandler = (FlowHandler) handler;
        checkAndPrepare(request, response, false);
        String flowExecutionKey = this.getFlowUrlHandler()
                .getFlowExecutionKey(request);
        if (flowExecutionKey != null)
            try {
                ServletExternalContext context = createServletExternalContext(
                        request, response);
                FlowExecutionResult result = this.getFlowExecutor().resumeExecution(
                        flowExecutionKey, context);
                handleFlowExecutionResult(result, context, request, response,
                        flowHandler);
            } catch(org.springframework.webflow.execution.repository.NoSuchFlowExecutionException ex){
                response.sendRedirect(request.getRequestURI());
            } catch(org.springframework.webflow.execution.repository.BadlyFormattedFlowExecutionKeyException ex){
                response.sendRedirect(request.getRequestURI());
            } catch (FlowException e) {
                handleFlowException(e, request, response, flowHandler);
            }
....

我在这里捕获 NoSuchFlowExecutionException 并重定向到没有任何参数的确切流 URL。在这里您可以捕获并重新包含您的参数

因此,我可以在任何状态下为我的 URL 添加书签(流程总是从第一个开始),如果需要,我也可以发送我自己的参数。

关于Spring Webflow 2 和可收藏的 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13626336/

相关文章:

java - 有没有办法将 @Scheduled 与 Duration 字符串(如 15s 和 5m)一起使用?

java - 无法在独立 Tomcat 8.5 上启动 Spring Boot 1.5.1 应用程序

spring - 在 Spring Security OAuth 中,您如何将 passwordEncoder 用于客户端 secret ?

html - 为什么 HTML5 header 元素需要 h 标签?

asp-classic - 经典 ASP 中的 PDF 保护和 SEO

url - foo.com/alice 与 foo.com/users/alice

.htaccess - 友好 URL(mod-rewrite)问题

java - Spring 单元测试 - 为不同的单元测试加载不同的配置文件

php - 如何使用 .htaccess 使长 URL 友好

node.js - 如何通过apache连接 Node 服务器?