简体   繁体   中英

Conditional form action in Struts

I wanted to have one jsp page conditionally post to two different Struts actions. So I wrote this:

<logic:notEmpty property="foo"> 
  <html:form action="modifyUser">
</logic:notEmpty>
<logic:empty property="foo"> 
  <html:form action="modifySelf">
</logic:empty>
the body of the page
</html:form>

As a result I got this

Compilation of JSP File '/tiles/user/modify.jsp' failed:

modify.jsp:8:2: No end tag found.
<html:form action="modifyUser">
 ^-------^
modify.jsp:8:2: No end tag found.
<html:form action="modifyUser">
 ^-------^
modify.jsp:11:2: No end tag found.
<html:form action="modifySelf">
 ^-------^
modify.jsp:11:2: No end tag found.
<html:form action="modifySelf">
 ^-------^
modify.jsp:109:3: No start tag found.
</html:form>
  ^-------^
modify.jsp:109:3: No start tag found.
</html:form>
  ^-------^

I am guessing that the parser is looking for forms before logic, or at least matching all the tags.

Any thoughts on how to get the same effect? I am running within tiles also.

One solution:

 <%String formAction=""; %>

 <logic:notEmpty property="foo"> 
  <% formAction="modifyUser" %>
 </logic:notEmpty>

 <logic:empty property="foo"> 
  <% formAction="modifySelf" %>
 </logic:empty>

 <html:form action="<%=formAction%>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM