Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
153 views
in Technique[技术] by (71.8m points)

java - How to handle multiple actions in a single form in Struts 2

I have a form contains three buttons print/export/save.

<s:form action="/userAction">
    <s:submit type="image" value="%{'print'}" src="/print.png" />
    <s:submit type="image" value="%{'export'}" src="/export.png" />
    <s:submit type="image" value="%{'save'}" src="/save.png" />
</s:form>

How can I map this in struts.xml?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

In the struts.xml the action is mapped via the action tag

<action name="userAction" class="...

the submit buttons should include method attribute to call corresponding methods of the action

<s:submit type="image" value="%{'print'}" src="/print.png" method="print" />
<s:submit type="image" value="%{'export'}" src="/export.png" method="export" />
<s:submit type="image" value="%{'save'}" src="/save.png" method="save" />

Note: To map a method attribute you should have DMI turned on.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.9k users

...