How to exclude the submit action from a list of parameters in struts2?

被刻印的时光 ゝ 提交于 2019-11-28 01:25:41
Roman C

Why doesn't it exclude the submit button's parameter?

Because this parameter is in the excludeParams list of the params interceptor in the defaultStack which your action is referenced by default.

How to invoke the postAction() method, when <s:submit> is clicked?

In this question you ask how to invoke a method (not an action). The difference between the action and method the first is mapped to a specified URL using a namespace and action name. So, to invoke a method other than an action you should turn DMI on. Struts, since 2.3.16 turned off this option. The following configuration constant to use in struts.xml:

<constant name="struts.enable.DynamicMethodInvocation" value="true"/>

and use a method attribute instead of action attribute.

<s:form namespace="/admin_side" action="test">
  <s:submit value="Submit" method="postAction"/>
</s:form> 

as I already told in this answer.

If you don't want to use DMI, then you have an option to enable action: prefix to the parameter

<constant name="struts.mapper.action.prefix.enabled" value="true"/>

and use an action mapped to the method postAction

<s:form namespace="/admin_side" action="test">
  <s:submit value="Submit" action="postAction"/>
</s:form> 

and use annotation without params.excludeParams.

@InterceptorRef(value="defaultStack" params={"validation.excludeMethods", "test"})

The warning that action:postAction parameter is on exclude list still persist, but it appears only if the struts.devMode=true. You shouldn't worry about it because it warns all parameters from the excludeParams list that passed through. To turn off devMode you should set

<constant name="struts.devMode" value="false" />
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!