Populating multiple forms in a Struts 1.x JSP

java, jsp, struts, struts-1

Solution

Yes, it's possible.

You could specify multiple `ActionForm` implementations for this issue (preferred) or use only one - no matter.

<nested:root name="myFirstForm">
    <nested:form action="/MyAction.do?method=foo" method="post">
        <%-- some code --%>
    </nested:form>
    <nested:form action="/MyAction.do?method=bar" method="post">
        <%-- some code --%>
    </nested:form>
</nested:root>
<nested:root name="mySecondForm">
    <nested:form action="/MyAction.do?method=foobar" method="post">
        <%-- some code --%>
    </nested:form>
</nested:root>

From Apache Struts Newbie FAQ:

Q: Do I have to have a separate ActionForm bean for every HTML form?

A: This is an interesting question. As a newbie, it is a good practice to create a new ActionForm for each action sequence.

Problem

Is there any way to populate multiple forms with Struts and make them available to the JSP page? I'm building a page that has two different forms on it that needs custom data pre-populated from a database. Both forms have to be on the same page.

Original source