Home > Java > javaTutorial > How to use jsp button

How to use jsp button

(*-*)浩
Release: 2020-09-19 13:49:28
Original
7551 people have browsed it

How to use jsp button

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';
      }
    });
  }
Copy after login

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>
Copy after login

Submit is a Button specially used to submit forms. There are two main differences with Button:

  • ##type=button is simply a button function

  • type=submit is to send the form

(1). Submit will submit the form (form.submit()) as the default event after its onclick. This is not the case for 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:

java basics

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!

Related labels:
jsp
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template