动态:表单动作

问题描述 投票:0回答:2

有没有办法在Struts2中的

action
标签中指定动态
s:form
属性?我想要像下面这样的东西。

<c:set var="formAction" value="baseAction" />
<c:if test="${someCondition}">
     <c:set var="formAction" value="childAction" />Ac

<s:form method="post" action="${formAction}">
    <s:input....../>
    <s:select...../>
</s:form>

我知道这可以使用 javascript 来实现,但我想避免重构。 我尝试使用 scriplet 来实现此目的,但问题是 Struts2 标签不采用 runtime attribute。我什至尝试了 OGNL,但也没有帮助。

jsp dynamic struts2 action ognl
2个回答
7
投票

使用Struts2标签设置值并检查条件,然后使用OGNL放置

action
属性。

<s:set var="formAction" value="'baseAction'" />
<s:if test="some_condition">
  <s:set var="formAction" value="'childAction'" />
</s:if>

<s:form method="post" action="%{#formAction}">
  <s:input....../>
  <s:select...../>
</s:form>

2
投票

使用

s:url
标签动态构建操作 URL。

<s:url action="%{somePoperty}" var="myUrl"/>
<s:form action="%{#myUrl}"> 

事实上,Struts 标签的属性不仅接受 scriptlet,还接受 JSTL EL 表达式。

© www.soinside.com 2019 - 2024. All rights reserved.