通过拦截器将 URL 查询字符串中的参数传递给 Action
Passing parameters in URL query string to Action through interceptor
我有一个工作正常的拦截器,只是查询字符串没有从拦截器传递到操作。
<action name="EditIroCase" class="iro.action.IroCaseAction">
<interceptor-ref name="authIro"/>
<result name="success">iro/IroCaseFORM.jsp</result>
</action>
URL: /EditIroCase.action?id=123
Action 是我要添加拦截器的现有 Action。在 Action
中实施 ParametersAware
以从 URL 获取 ID,并且工作正常。
尝试了几种不同的方法,但似乎无法正常工作。使用了很多拦截器,只是从不需要在其执行过程中维护参数。
Interceptors 工作略有不同而不是动作。因为他们属于行动。所以不能给拦截器加action,而是给action加拦截器。
你应该知道,如果你使用的是xml配置或注解,或其他配置提供者,拦截器存储在集合中,如List
或Set
,无所谓,但所有这些都在一个地方。在 <action>
中使用 <interceptor-ref>
标签会覆盖 拦截器的配置。默认情况下,操作是使用 <default-interceptor-ref>
标记配置的,该标记在核心包的 struts-default.xml
中定义,它指向 defaultStack
。此堆栈旨在满足您的所有需求,但如果您使用自定义拦截器,则应显式添加对 defaultStack
的引用或创建您要引用的自定义堆栈。
<action name="EditIroCase" class="iro.action.IroCaseAction">
<interceptor-ref name="authIro"/>
<interceptor-ref name="defaultStack"/>
<result name="success">iro/IroCaseFORM.jsp</result>
</action>
现在应该填充参数。
我有一个工作正常的拦截器,只是查询字符串没有从拦截器传递到操作。
<action name="EditIroCase" class="iro.action.IroCaseAction">
<interceptor-ref name="authIro"/>
<result name="success">iro/IroCaseFORM.jsp</result>
</action>
URL: /EditIroCase.action?id=123
Action 是我要添加拦截器的现有 Action。在 Action
中实施 ParametersAware
以从 URL 获取 ID,并且工作正常。
尝试了几种不同的方法,但似乎无法正常工作。使用了很多拦截器,只是从不需要在其执行过程中维护参数。
Interceptors 工作略有不同而不是动作。因为他们属于行动。所以不能给拦截器加action,而是给action加拦截器。
你应该知道,如果你使用的是xml配置或注解,或其他配置提供者,拦截器存储在集合中,如List
或Set
,无所谓,但所有这些都在一个地方。在 <action>
中使用 <interceptor-ref>
标签会覆盖 拦截器的配置。默认情况下,操作是使用 <default-interceptor-ref>
标记配置的,该标记在核心包的 struts-default.xml
中定义,它指向 defaultStack
。此堆栈旨在满足您的所有需求,但如果您使用自定义拦截器,则应显式添加对 defaultStack
的引用或创建您要引用的自定义堆栈。
<action name="EditIroCase" class="iro.action.IroCaseAction">
<interceptor-ref name="authIro"/>
<interceptor-ref name="defaultStack"/>
<result name="success">iro/IroCaseFORM.jsp</result>
</action>
现在应该填充参数。