2

我有一个 Struts2 应用程序,它的操作可能需要 1 秒到 5 分钟才能运行。因此,如果操作运行时间超过 20 秒,我将使用 execAndWait 拦截器显示等待页面。操作的设置如下所示:

<action name="myAction" class="myActionClass">
    <interceptor-ref name="defaultStack" />
    <interceptor-ref name="execAndWait">
       <param name="delay">20000</param>
    </interceptor-ref>
    <result name="success">myPage.jsp</result>

    <result name="wait">waitPage.jsp</result>
</action>

我已经在一个动作只需要 1 秒的情况下对此进行了测试。我希望永远不会显示等待页面。

但是,等待页面仍然出现。我尝试调试我的操作类和方法,发现执行在下面的这条语句处挂起,持续了

<param name="delay">

在这种情况下,它在下面的语句处等待 20 秒,然后成功完成执行。

getSession().put(A_SESSION_VARIABLE, 10);

注意:MyActionClass 确实实现了 SessionAware

有没有其他人遇到过这个问题?有解决办法吗?

4

2 回答 2

2

A workaround (if your action is used in a servlet environment): implement ServletRequestAware interface and use HttpServletRequest to get session.

request.getSession().setAttribute(A_SESSION_VARIABLE, 10);
于 2013-06-21T12:03:07.527 回答
0

I have a different approach for this problem. You can run the heavy processing in a separate thread and return the response to the user instantly stating that the work is in progress. When the work is finished you can return whatever you want to return to the user. This can be achieved by using polling.

In the meantime user don't have to wait and can do other stuff.

Hope it helps.

于 2013-06-20T16:13:37.650 回答