How to use struts2 submit tag as button without submitting the form?(如何在不提交表单的情况下使用struts2提交标签作为按钮?)
问题描述
我在我的应用程序中使用 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.我表单的主题是 Ajax.
1) If I use the HTML button tag it will mess the GUI. As theme of my form is Ajax.
这是一个带有脚本的head标签
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>
我的 body 标签是关注者:
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.
非常感谢您的帮助.
推荐答案
如果你使用 s:submit 标签,渲染的 HTML 输出是 input 或 button 标签,但类型是 submit 除了 image 类型.您可以使用代码执行不提交表单的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;"/>
这篇关于如何在不提交表单的情况下使用struts2提交标签作为按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在不提交表单的情况下使用struts2提交标签作为按钮?
- Eclipse 插件更新错误日志在哪里? 2022-01-01
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- 如何使用WebFilter实现授权头检查 2022-01-01
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
- C++ 和 Java 进程之间的共享内存 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01
