如何使用Struts2的提交标记为按钮不提交表单?表单、如何使用、标记、按钮

由网友(栖迟)分享简介:我使用Struts2框架在我的应用程序,我对我的JSP页面的一个按钮。这就是I am using Struts2 framework in my application, I have one button on my JSP page. That is我使用Struts2框架在我的应用程序,我对我的JSP页面的一个按钮。这就是

I am using Struts2 framework in my application, I have one button on my JSP page. That is

<s:submit type="button" name="btnSave" />

现在,我想这个按钮的行为与普通的HTML按钮类型不能提交表单并执行脚本 函数的onclick 事件。使用Ajax功能提交表单。

Now, I want this button to behave as normal HTML button type should not submit the form and execute the Scripting function on onclick event. That function submit the form using Ajax.

但是,什么情况是Struts2的将其转换成

But what happens is Struts2 convert it to

<input type="submit" id="add_btnSave" name="btnSave" value="Save"/>

和我的表单提交。

1)如果我使用HTML按钮标记它会乱的GUI。由于我的表单主题是阿贾克斯。

1) If I use the HTML button tag it will mess the GUI. As theme of my form is Ajax.

这是一个用script标签

This is a head tag with script

<head>
<s:head theme="ajax"/>
<script type="text/javascript">

$("btnSave").click(function(){
alert("aaa");
$.ajax({
url:
type:"POST",
dataType: "json",
error: function(XMLHttpRequest, textStatus, errorThrown){
alert('Error ' + textStatus);
alert(errorThrown);
alert(XMLHttpRequest.responseText);
},
success: function(){
alert('SUCCESS');
}
});
});
</script>
</head>

我的标签是作为追随者:

My body tag is as followers :

<body>
<table border="1" width="80%" align="center">
<tr>
<td width="100%">
<s:tabbedPanel id="EmpDetail" useSelectedTabCookie="true">
<s:div id="one" label="Emp Reg." theme="ajax" tabindex="0" labelposition="top">
<center>
<s:form name="frmEmpReg" namespace="/" method="post">
EMPLOYEE REGISTRATIOM TAB<br>
<s:actionmessage />
<input type="hidden" name="empbean.id" value="<s:property value="empbean.id"/>"/>
<s:textfield label="Employee First Name" name="empbean.firstName"></s:textfield>
<s:textfield label="Employee Middle Name" name="empbean.middleName"></s:textfield>
<s:textfield label="Employee Last Name" name="empbean.lastName"></s:textfield>
<s:textfield label="Address" name="empbean.address"></s:textfield>
<s:textfield label="State" name="empbean.state"></s:textfield>
<s:textfield label="Employee Designation" name="empbean.designation"></s:textfield>
<s:submit name="btnSave" type="submit" value="Save" align="center"/>
</s:form>
</center>
</s:div>
<s:div>
..
..
Other Tabs
</s:div>
</s:tabbedPanel>
</td>
</tr>
</table>
</body>

任何一个有与Struts2的处理它,那么请帮助任何想法。

any one have any idea of handling it with Struts2 then please help.

您的帮助将是非常美联社preciated。

Your help will be really appreciated.

推荐答案

如果您使用的是 S:提交标记呈现 HTML 输出或者输入按钮标签,但该类型提交除了图片键入。你可以用code到执行不提交表单的JavaScript onclick事件。

If you are using s:submit tag the rendered HTML output is either input or button tag but the type is submit except for the image type. You can use the code to execute javascript onclick event that doesn't submit the form.

<s:submit type="button" onclick="return false;"/>
阅读全文

相关推荐

最新文章