传递数组的.jsp到.JSP [英] Pass Array .jsp to .jsp
问题描述
我想知道如何通过一个数组或从一个的.jsp网页到另一个列表。我想,然后从这个阵列获取的值,并将其分配给一个JavaScript数组。我想我已经正确配置源jsp页面,但不知道如何获得第二的.jsp页面中的值。
这是我的源.jsp文件:
< HTML和GT;
< HEAD>
< META HTTP-EQUIV =Content-Type的CONTENT =text / html的;字符集= ISO-8859-1>
<标题> Firstjsp< /标题>
< /头>
<身体GT;
<形式方法=邮报行动=Mapper.jsp>
&所述;%字符串位置[] = {贷款1,33.890542,151.274856,地址1,真,-35404.34};
的for(int i = 0; I< locations.length;我++)
{
%GT;
<输入类型=隐藏的名字=LOCVALUE =<%=位置[I]%GT;>
<%
}
%GT;
< /表及GT;
< /身体GT;
< / HTML>
您可以用得到它们的 的HttpServletRequest#getParameterValues()
。这将返回有相同的参数名称的所有参数值的字符串数组。在你的情况,你已经产生了第一个JSP使用相同的名称位置
几个隐藏的HTML输入元素,所以在第二个JSP以下(或preferably,一个的servlet )应该做的:
的String [] =位置request.getParameterValues(LOC);
I am wondering how to pass an array or a list from one .jsp page to another. I want to then take the values from this array and assign them to a javascript array. I think I have the source jsp page configured correctly, but was wondering how to get the values in the second .jsp page.
This is my source .jsp file:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Firstjsp</title>
</head>
<body>
<Form Method = "Post" Action = "Mapper.jsp">
<% String locations[] = {"Loan 1", "33.890542", "151.274856", "Address 1","true", "-35404.34"};
for (int i =0; i<locations.length; i++)
{
%>
<Input type = "Hidden" name = "loc" value = "<%= locations[i] %>">
<%
}
%>
</Form>
</body>
</html>
You can get them using HttpServletRequest#getParameterValues()
. This returns a string array of all parameter values which have the same parameter name. In your case, you have generated several hidden HTML input elements with the same name loc
in the first JSP, so the following in the second JSP (or, preferably, a servlet) should do:
String[] locations = request.getParameterValues("loc");
这篇关于传递数组的.jsp到.JSP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!