没有@EndConversation的Struts 2会话范围插件

时间:2013-11-06 07:21:57

标签: java struts2 struts2-convention-plugin

考虑下面的例子,我认为这是一个非常常见的步骤形式样本。 我有一个三步形式,想要从一个帐户转账到其他:

First  page gets user source account
Second page shows source account and gets destination account and the amount
Last   page shows a confirmation which mention source account + destination account + amount

如您所见,我也需要最后一页中的模型信息。因此,我使用@BeginConversation作为第一个操作,使用@ConversationAction作为第二页和最后一页。

问题是我的行为都没有用@EndConversation注释。可以吗?! 模型是否会驻留在内存中,还是会自动清理?我无法找到什么时候自动清洁。

1 个答案:

答案 0 :(得分:2)

我遇到了类似的问题。如果通过表单提交调用我的结束操作,我总是会收到错误消息,说明对话已关闭或已过期。

当然,如果您没有完成对话,则不会释放内存资源。您可以在strut2对话插件网站中获取有关此内容的一些信息:https://code.google.com/p/struts2-conversation/wiki/UsageGuide#Memory_Management

在那里你可以看到可以设置一些与会话线程到期相关的参数以及可以同时使用它们的数量:

<!-- monitoring frequency in milliseconds -->
<constant name="conversation.monitoring.frequency" value="300000"/>

<!-- idle conversation timeout in milliseconds -->
<constant name="conversation.idle.timeout" value="28800000"/>

<!-- max instances of a conversation -->
<constant name="conversation.max.instances" value="20"/>

<!-- number of timeout monitoring threads -->
<constant name="conversation.monitoring.thread.pool.size" value="20"/>

无论如何,我解决了这个问题,在最后一个动作中添加了重定向结果,该动作调用包含@EndConversation标记的动作。在其中我只是设置了我想成为最后一个的结果。会话字段变量仍然是正确设置和可用的。

@ConversationAction(conversations = "form")
@Action(value="formSecondLast", results={@Result(name=SUCCESS, type = "redirect", location="formLast")})
public String formSecondLast() throws Exception {
    //Here goes the code you want it to manipulate the conversation field data.
    //Maybe save to the database or send it to the business tier.
    return SUCCESS;
}

@EndConversation(conversations = "form")
@Action(value="formLast", results={@Result(name=SUCCESS, location="/jsp/form-end.jsp")})
public String formEnd() throws Exception {
    // This is a dummy action that does not do anything.
    // It is called just after formSecondLast ends and sends the user the jsp page.
    return SUCCESS;
}
相关问题