There are two pages:
1. create. jsp
Copy codeThe Code is as follows:
<% @ Page language = "java" import = "java. util. *" pageEncoding = "UTF-8" %>
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html>
<Title>
</Title>
<Head>
</Head>
<Body>
<Form id = "form1" action = "request. jsp">
<Script language = "javascript" type = "text/javascript">
Var count = 0;
Function additem (id)
{
Var row, cell, str;
Row = document. getElementByIdx_x (id). insertRow ();
If (row! = Null)
{
Cell = row. insertCell ();
Cell. innerHTML = "<input id = \" St "+ count +" \ "type = \" text \ "name = \" St "+ count +" \ "value = \" st "+ count +" \ "> <input type = \" button \ "value = \" delete \ "onclick = \ 'deleteitem (this ); \ '> ";
Count ++;
}
}
Function deleteitem (obj)
{
Var curRow = obj. parentNode. parentNode;
Tb. deleteRow (curRow. rowIndex );
}
Function getsub ()
{
Var re = "";
For (var I = 0; I <count; I ++)
{
Re + = document. getElementsByName ("St" + I) [0]. value;
}
Document. getElementByIdx_x ("Hidden1"). value = re;
}
</Script> <table id = "tb"> </table>
<Input name = "button" type = "button" onclick = 'additem ("tb ") 'value = "add>"/> <input type = "submit" name = "submit" onclick = "getsub ()" value = "submit"/>
<Input id = "Hidden1" name = "Hidden1" type = "hidden" value = ""/>
</Form>
</Body>
</Html>
Ii. Receiving data page request. jsp
Copy codeThe Code is as follows:
<% @ Page language = "java" import = "java. util. *" pageEncoding = "UTF-8" %>
<Html>
<Head>
<Title> test </title>
</Head>
<%
String data = request. getParameter ("Hidden1 ");
Out. println ("the obtained data is:" + data );
%>
<Body>
</Body>
</Html>