Search code examples
htmlformsstrutssubmitstruts-action

Struts html:form with different actions


I have a jsp with a submit based on the html:form action.

<html:form action="/nextPath">

I want to set the action based on a variable, or current path.. etc

<d:isActionPath path="/path1" >
    <html:form action="/nextPath1">
</d:isActionPath>

<d:isActionPath path="/path2" >
    <html:form action="/nextPath2">
</d:isActionPath>

This does not work. But this is essentially want I want to do.

Any suggestions? Very new to struts.


Solution

  • <d:isActionPath path="/path1" >
        <c:set var="theAction" value="/nextPath1"/>
    </d:isActionPath>
    
    <d:isActionPath path="/path2" >
        <c:set var="theAction" value="/nextPath2"/>
    </d:isActionPath>
    
    <html:form action="${theAction}">
        ...
    </html:form>
    

    JSP tags must be balanced correctly, as in a XML document. You can't open a tag d:isActionPath, open a tag html:form and close the d:isActionPath tag without having closed the html:form tag.