Home  >  Article  >  Java  >  How to use jsp button

How to use jsp button

(*-*)浩
(*-*)浩Original
2019-05-20 13:54:177490browse

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

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:

  • ##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!

Statement:
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