2012-03-30 49 views
0
<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的标签提交按钮

我有这个表由Struts2的标签。

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

请告诉我怎么做?

回答

0

你为什么不使用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还提供了另一种方式来处理多个提交按钮在你的页面,请参阅文件的细节