The buttons of jsp should be these two kinds of button and submit. Today I will let us see how to use them.
1. Button: You can format the returned data and reflect it on the page. You can use the form form serialization to submit it or you can submit it without the form form.
form form submission
<form id="addForm"> <input type="hidden" placeholder="用户id" id="id" name="id"/> <input type="button" value="保存" onclick="addUser()"> <script type="text/javascript"> function addUser(){ $.ajax({ type:'post', // data:$("#addForm").serialize(), data:{id:$("#id").val()}, url:'<%=ctxPath%>/doSave', success:function(data){ alert("保存成功!"); window.location.href='<%=ctxPath%>/home'; } }); }
2. Submit: Specially used for form form submission, the returned data cannot be formatted, and the form form must be used Submit
<form id="addForm" method="post" action="<%=ctxPath%>/doSave"> <input type="hidden" placeholder="用户id" id="id" name="id"/> <input type="submit" value="保存"> </form>
Submit is a Button specially used to submit forms. There are two main differences with Button:
(2) When the form is submitted, all html input elements with name attributes (including input tags, button tags, select tags, etc.) will be submitted as key-value pairs, except for the Submit object. The Submit object will only be submitted as a key-value pair in the submission after it is clicked.
Related learning recommendations:
The above is the detailed content of How to use jsp button. For more information, please follow other related articles on the PHP Chinese website!