Jsp:javascript implementation input Multi-line dynamic input

Source: Internet
Author: User
Tags array html page string
javascript|js| Dynamic General, we use
Request.getparameter ("value");
To get the value of the static HTML input. Then don't forget to judge whether it is empty, whether it contains special characters, etc.

can also use
Enumeration Paramnames=request.getparameternames ();
while (Paramnames.hasmoreelements ()) {string paramname= (String) paramnames.nextelement ();}
To collect name from the <input type= "text" name= "name"/>

But each new line we add, the parameter name is the same as the previous line, so how do we get the value?
Here I went to read (Servlet and JSP core programming, a very good book, it is said, read and understand it servlet/jsp can also say proficient) p70 page: Getparametervalues () returns an array of strings, Then we use the loop to determine the length of the string array, and then we get the value:


Request.getparameter ("value");//This is the most familiar, get the value of the text box
(enumeration) request.getparameternames ();//Get the name of the text box
(string[]) request.getparametervalues (paramname);//Get the value of the same argument (multiple occurrences) of the static HTML page

HTML page JavaScript code:
<script language= "JavaScript" >
function Tbladdrow ()
{
var i=lines.rows.length;
var row = Table1.insertrow (Table1.rows.length);
var col = Row.insertcell (0);
col.innerhtml = "<input id=line[" +i+ "][name1" Name=line "+i+ name1";
Col = Row.insertcell (1);
col.innerhtml = "<input id=line[" +i+ "][name2" Name=line "+i+ name2";
Col = Row.insertcell (2);
col.innerhtml = "<input id=line[" +i+ "][name3" Name=line "+i+ name3";
Col = Row.insertcell (3);
col.innerhtml = "<input id=line[" +i+ "][name4" Name=line "+i+ name4";
}
function Tbladdrows (items)
{
for (i = 1; I <= items; i++)
{
Tbladdrow ();
}
}
function Delrow ()
{
if (lines.rows.length==0)
{
return false;
}
Lines.deleterow ();
}

</script>

HTML page other code:
<meta http-equiv= "Content-type" content= "text/html; Charset=big5 ">
<title> input </title>
<body>
<form action= "getinput.jsp" >
<div align=center><font size=2> Input tests </FONT></DIV></TD>
&LT;TD width=412 bgcolor= #e4e4e4 >
<table id=table1 cellspacing=0 bordercolordark= #ffffff cellpadding=0
width=350 align=center bordercolorlight= #000000 border=1>
<TBODY>
<tr bgcolor= #999999 >
<th Width=94><font size=2> a </FONT></TH>
<th width=84><font size=2> Parameters two </FONT></TH>
<th Width=85><font size=2> Reference three </FONT></TH>
<th width=77><font size=2> Parameters four </FONT></TH></TR>
<tbody id=lines name= "lines" ><!--
<TR>
<td><input id= "Things_name" type= "text" name= "Things_name" size= "></TD>"
<td><input id= "Things_model" type= "text" name= "Things_model" size= "ten" ></TD>
<td><input id= "Things_number" type= "text" name= "Things_number" size= "5" ></TD>
<td><input id= "Things_unit" type= "text" name= "Things_unit" size= "5" ></TD>
</TR>
--></tbody></table>
<div align=center><br></div>
<div align=center>
<input id=items Type=hidden value=1 name=items> <input (Onclick=tbladdrow);

Type=button value= New Line name=insert/>
<font color= "#e4e4e4" > </font>
<input language=javascript Type=button value= Delete Row name=del/>
</DIV></TD></TR></TBODY></TABLE>
<input type= "Submit" value= "Commit"/>
</form>
</body>

JSP Page Collection input
<%@ page contenttype= "Text/html;charset=big5"%>
<%@ page import= "java.util.*"%>

<%
Request.setcharacterencoding ("Big5");

Enumeration Paramnames=request.getparameternames ();
String Paramname=null;
while (Paramnames.hasmoreelements ()) {
Paramname= (String) paramnames.nextelement ();

String Param=request.getparameter (paramname);

Out.println (paramname+ "" +param+ "<br>");

String paramvalues[]=request.getparametervalues (paramname);
for (int i=0; i<=paramvalues.length-1; i++)
{
Out.println (paramname+ "");
Out.println (paramvalues[i]+ "<br>");}

}



Out.println ("<br>" +name);

%>
<meta http-equiv= "Content-type" content= "text/html; Charset=big5 ">
<title> Accept Input </title>
<body>
</body>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.