0

I am using Struts2 and an action implementing the Preparable interface.

When I submit the form, action properties are not being set in prepare() method of action. I get the values in the action method (eg. execute()), but they are empty in the prepare() method.

How can I get the properties set before running the prepare() method ?

4

1 回答 1

1

在默认的拦截器堆栈中,准备拦截器在参数拦截器之前运行。prepare()这意味着当 Prepare Interceptor 执行该方法时,参数的注入尚未发生。您需要将参数拦截器移动到准备拦截器之前,或者复制它,在准备拦截器之前放置一个声明。

为此目的创建了一个默认的拦截器堆栈paramsPrepareParamsStack在此处此处阅读更多信息。

请注意,此类问题在 Struts2 中经常出现,您需要了解 Interceptor Stack 的工作原理以及每个 Interceptor 处理的业务。

例如,在使用 ModelDriven使用 Wildcard Mapping 时会发生这种情况。如果你把它们放在错误的地方,你的自定义拦截器肯定会发生这种情况。

于 2015-05-21T07:43:40.337 回答