如何在jsp中获取数组值
how to get the array values in jsp
当我在JSP文件中使用request.getParameter("quantity")
时,仅返回作为输出的数组中的最后一个值。如何将整个数组及其所有值传递给JSP文件?
myfile1.js:
function savetheChanges()
{
for(var i=0;i<16;i++)
{
quants[i]=document.getElementById("quantity"+i).value;
kot1[i]=document.getElementById("kot"+i).value;
itemcode1[i]=document.getElementById("itemcode"+i).value;
var billno=document.getElementById("billno").value;
document.detailsview.action ="BillCB.jsp?method=" + "17" + "&billno=" +billno+ "&itemcode=" +itemcode[i]+ "&kot=" +kot1[i]+ "&quantity="+quants[i];
}
}
myfile2.jsp:
(在获取值时,我只获得数组的前两个元素)
billdetails_be.billno = Integer.valueOf(request.getParameter("billno"));
String[] quantCB = request.getParameterValues("quantity");
String[] kotCB = request.getParameterValues("kot");
String[] itemCB = request.getParameterValues("itemcode");
int[] quantarr = new int[quantCB.length];
int[] kotarr = new int[kotCB.length];
int[] itemarr = new int[itemCB.length];
System.out.println("beforeloop " + itemarr.length);
for (int i = 1; i < quantarr.length; i++) {
quantarr[i] = Integer.parseInt(quantCB[i]);
}
for (int i = 1; i < kotarr.length; i++) {
kotarr[i] = Integer.parseInt(kotCB[i]);
}
for (int i = 1; i < itemarr.length; i++) {
itemarr[i] = Integer.parseInt(itemCB[i]);
}
for (int i = 1; i < itemarr.length; i++) {
int quantint = quantarr[i];
int kotint = kotarr[i];
int itemint = itemarr[i];
System.out.println("value in array:" + (quantarr[i]));
}
function savetheChanges()
{
var quantity = new array[];
for(var i=0;i<16;i++)
{
quantity[i]=document.getElementById("quantity"+i).value;
}
document.detailsview.action ="BillCB.jsp?method=" + "17" + "&billno=" +billno+ "&quantity="+quantity;
}
在查询字符串中传递数组一次,然后
使用request.getParameterValues("quantity")
它会给你数组
<%
String[] favouriteCars = request.getParameterValues("favouritecar");
for (int i = 0; i < favouriteCars .length; i++) {
String car = favouriteCars [i];
System.out.println("car name::"+car);
%>
上面的代码将获得所有的汽车并打印到jsp上,或者您也可以使用JSTL
在jsp
相关文章:
- 获取数组的总值
- 按最大值获取数组索引
- React.js如何从js文件中获取数组
- TinyMCE获取数组数据
- 如何获取数组详细信息另一页
- 使用javascript从节点属性获取数组值
- 使用JavaScript获取数组中表单的所有控件
- 获取数组的长度-打印不正确的值
- 正在从JSON对象获取数组
- 什么'获取数组的已定义部分的最快方法是什么?JS
- 如何使用angular指令从html中获取数组
- 如何获取数组中数字的最大出现次数
- 根据优先级获取数组的值
- JAVASCRIPT:获取数组中的值
- 获取数组的元素,无论索引的大小如何
- JavaScript:在XML中搜索节点并从该节点获取数组
- 无法获取数组的长度
- 在数字索引循环中获取数组项的键
- 如何使用JavaScript或jQuery获取数组中选定的optgroup和选项
- Javascript-函数获取数组元素参数未定义/为null