<%@ Page Language="Java"Import="java.util.*"pageencoding="UTF-8"%><%StringPath=Request.getcontextpath ();StringBasePath=Request.getscheme ()+"://"+Request.getservername ()+":"+Request.getserverport ()+Path+"/";%><!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en"><HTML> <Head> <Basehref= "<%=basePath%>"> <title>File Upload</title> <Metahttp-equiv= "Pragma"content= "No-cache"> <Metahttp-equiv= "Cache-control"content= "No-cache"> <Scripttype= "Text/javascript"src= "Script/jquery.min.js"></Script> <Scripttype= "Text/javascript"> $(function(){ varI=2; //1. Get #addfile, add click event $("#addFile"). Click (function(){ //2. The build node is placed in front of the #br /*The node is set as follows: <tr><td>file2:</td><td><input type= "file" Name= "File2" /></td></tr> <tr><td>desc2:</td><td><input type= "text" Name= "DESC2 "/></td></tr>*/ varinnerHtml= "<tr><td>file"+I+": </td><td><input type= ' file ' name= ' file"+I+"'/></td></tr>"+ "<tr><td>desc"+I+": </td><td><input type= ' text ' name= ' desc"+I+"'/><button type= ' button ' > delete </button></td></tr>"; $("#end"). Before (innerHtml). Prev ("TR"). Find ("Button"). Click (function() {alert (123); $( This). Parents ("TR"). Prev ("TR"). Remove (); $( This). Parents ("TR"). Remove (); I--; }); I++; }); }); </Script> </Head> <Body> <FontColor= "Red">${message}</Font> <BR/><BR/> <formAction= "Uploadservlet"Method= "POST"enctype= "Multipart/form-data"> <Table> <TR> <TD>File1:</TD> <TD><inputtype= "File"name= "File1"/></TD> </TR> <TR> <TD>DESC1:</TD> <TD><inputtype= "text"name= "DESC1"></TD> </TR> <TRID= "End"> <TD><inputtype= "Submit"value= "Submit"/></TD> <TD><ButtonID= "AddFile"type= "button">Add an attachment</Button></TD> </TR> </Table> </form> </Body></HTML>
When the form form <button> type= "button" is not set, the button is clicked, the form is automatically submitted to Uploadservlet, and the bug no longer appears when the Type property is added to <button>
Click Submit Form when button is not set type value in form