質問

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.

役に立ちましたか?

解決

<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.

他のヒント

I had a similar problem:

Cannot retrieve mapping for action /${theAction}

I replaced ${theAction} by <%= theAction %> and it worked for me (struts 1.2.9, J2SE-1.5 and jboss-4.2.3.GA).

So you may try something like:

<% String theAction = "/nextPath"; %>
<d:isActionPath path="/path1" >
    <% theAction = "/nextPath1"; %>
</d:isActionPath>

<d:isActionPath path="/path2" >
    <% theAction = "/nextPath2"; %>
</d:isActionPath>

<html:form action="<%= theAction %>">
    ...
</html:form>

Edit: I’m confuse actually, why is it working with the <%= %> notation? Is it because the html tag is not interpreted correctly?

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top