【问题标题】:Struts2 : How to determine action dynamically with Struts2 Tag Submit buttonStruts2:如何使用 Struts2 标签提交按钮动态确定操作
【发布时间】:2012-03-30 03:58:08
【问题描述】:
<head>
<title>Struts 2 Login Application!</title>
</head>
<body>
<s:form action="login" method="POST" validate="true">
<tr>
<td colspan="2">
Login
</td>
</tr>
<s:actionerror />
<s:fielderror />
<s:textfield name="username" label="Login name"/>
<s:password name="password" label="Password"/>
<s:submit value="Login" align="center"/>
<s:submit value="Logout" align="center"/>
</s:form>
</body>
</html>

你好,

我有这个由 Struts2 标签组成的表单。

我的问题是,如何动态确定操作?意思是当用户点击登录提交按钮时,它应该调用动作登录,如果用户点击注销提交按钮,它应该调用动作注销?

请告诉我该怎么做??

【问题讨论】:

    标签: struts2


    【解决方案1】:

    你为什么不使用 URL 标签来处理这样的用例,这将为你提供更多的灵活性和易用性,你所要做的就是像

    <s:url id="login" action="login" method="login"> </s:url>
    <s:url id="logout" action="logout" method="logout"> </s:url>
    

    使用提交标签的动作属性的替代方法你必须在提交按钮中提供动作

    <s:submit value="Logout" align="center" action="logout"/>
    

    S2还提供了另一种方式来处理页面中的多个提交按钮,详情请参考文档

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-12-11
      • 2014-05-14
      • 2014-03-03
      • 2013-03-18
      • 2013-06-30
      • 2012-12-07
      相关资源
      最近更新 更多