[英]ArrayIndexOutOfBoundsException when use getParameterValues in Servlet
Here is is my HTML ..... 这是我的HTML .....
I take one input for count how many input .. and then highest four entry can be given.... 我拿一个输入来计算输入多少...然后可以给出最高的四个输入....
No Of Members: <select name="member" class="form-control">
<option value="0">Select</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
<table class="table table-bordered">
<tbody>
<tr>
<td><input type="text" name="studentid" class="form-control" id="" placeholder="Enter Student ID"></td>
<td><input type="text" name="name" class="form-control" id="" placeholder="Enter Name"></td>
<td><input type="text" name="email" class="form-control" id="" placeholder="Enter Email"></td>
<td><input type="text" name="cgpa" class="form-control" id="" placeholder="Enter CGPA"></td>
<tr/>
<tr>
<td><input type="text" name="studentid" class="form-control" id="" placeholder="Enter Student ID"></td>
<td><input type="text" name="name" class="form-control" id="" placeholder="Enter Name"></td>
<td><input type="text" name="email" class="form-control" id="" placeholder="Enter Email"></td>
<td><input type="text" name="cgpa" class="form-control" id="" placeholder="Enter CGPA"></td>
<tr/>
<tr>
<td><input type="text" name="studentid" class="form-control" id="" placeholder="Enter Student ID"></td>
<td><input type="text" name="name" class="form-control" id="" placeholder="Enter Name"></td>
<td><input type="text" name="email3" class="form-control" id="" placeholder="Enter Email"></td>
<td><input type="text" name="cgpa" class="form-control" id="" placeholder="Enter CGPA"></td>
<tr/>
<tr>
<td><input type="text" name="studentid" class="form-control" id="" placeholder="Enter Student ID"></td>
<td><input type="text" name="name" class="form-control" id="" placeholder="Enter Name"></td>
<td><input type="text" name="email" class="form-control" id="" placeholder="Enter Email"></td>
<td><input type="text" name="cgpa" class="form-control" id="" placeholder="Enter CGPA"></td>
<tr/>
</tbody>
</table>
My Servlet 我的Servlet
At first i take member no at a int type variable.. and then all the four field in four different array by getParameterValues. 首先,我在一个int类型变量中取成员no ..然后通过getParameterValues取四个不同数组中的所有四个字段。
try{
int member=Integer.parseInt(request.getParameter("member"));
String stdID[]=request.getParameterValues("studentid");
String name[]=request.getParameterValues("name");
String email[]=request.getParameterValues("email");
String cgpa[]=request.getParameterValues("cgpa");
for(int i=0;i<=member;i++){
System.out.println(stdID[i]+name[i]+email[i]+cgpa[i]);
}
}catch(Exception e){
System.out.println(e);
e.printStackTrace();
}
When i run this code and select No member (4) and fill all the field and then press submit.... 当我运行此代码并选择No member(4)并填写所有字段然后按提交....
In my console below errors show 在我的控制台下面显示错误
How can i solve this ? 我怎么解决这个问题? any idea ?
任何想法 ?
for(int i=0;i<=member;i++){
to 至
for(int i=0;i<member;i++){
why have you changed the email to email3 in the third entry? 为什么你在第三个条目中将电子邮件更改为email3?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.