Struts2 - Action class configuration

半城伤御伤魂 提交于 2020-01-07 07:59:08

问题


I have one JSP page which has two forms with submit buttons. How to configure different action class those two forms?

For example: form1 submit button configuration to classA and form2 submit button configuration to classB. Is it possible?


回答1:


As easy as:

<s:form>
    ...
    <s:submit action="Action1" />
</s:form>

<s:form>
    ...
    <s:submit action="Action2" />
</s:form>

You can even use different <s:submit> buttons for the same <s:form>

<s:form>
    ...
    <s:submit action="Action1" />
    <s:submit action="Action2" />
</s:form>



回答2:


Forms and buttons are mapped to the actions, actions are mapped to the methods of classes.

You have many but not nested forms in the JSP that could map to the action using the action attribute. The button "submit" should normally not include any of action or method attribute, that means it might invert the direction the action it communicates dynamically.

To use this feature with the default action mapper you have a DMI turned on.

You could have many actions mapping to the same method but different names but you couldn't have an action in the same namespace to map different classes or methods except that those classes or methods should be in the different namespaces.

The same thing for the form, you could map the form or button with any action, but only one and many forms could map to the same action, so you couldn't map the form with different action, you should map the button, or javascript with the action to change the direction the form mapped to.



来源:https://stackoverflow.com/questions/17157600/struts2-action-class-configuration

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