a.jsp:
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%
String[] arr = request.getParameterValues("cartid");
out.println(arr.length);
for (int i = 0; i < arr.length; i++) {
String str = arr[i];
out.println(str);
}
%>
text.jsp:
<pre name="code" class="html"><%@ page language="java" import="java.util.*"
contentType="text/html; charset=utf-8"%>
<%
//获取数组
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title></title>
<link href="css/proshopping.css" rel="stylesheet" type="text/css" />
<script src="js/jquery-1.8.2.min.js"></script>a
</head>
<body
<table id="main">
<tbody>
<tr id="id1">
<td href="#">一</td>
<td href="#">二</td>
<td href="#">三</td>
<td href="#">四</td>
</tr>
<tr id="id2">
<td href="#">一</td>
<td href="#">二</td>
<td href="#">三</td>
<td href="#">四</td>
</tr>
<tr id="id3">
<td href="#">一</td>
<td href="#">二</td>
<td href="#">三</td>
<td href="#">四</td>
</tr>
<tr id="nimei">
<td href="#">一</td>
<td href="#">二</td>
<td href="#">三</td>
<td href="#">四</td>
</tr>
</tbody>
</table>
<input type="button" value="Test" οnclick="AddToArr();">
</body>
<script>
function AddToArr() {
var arr = new Array();
$('tbody tr').each(function(i) {
arr[i] = this.id;
});
alert('Length:' + arr.length + '\nContent:' + arr);
var join = arr.join();//js是不能传递数组的,必须使用join将数组序列化
window.location = "a.jsp?Content="+join;
}
</script>
<div id="main">
<a id="id1" href="#">一</a> <a id="id2" href="#">二</a> <a id="id3"
href="#">三</a> <a id="id4" href="#">四</a>
</div>
<input type="button" value="Test" οnclick="AddToArr();">
</body>
<script>
function AddToArr(){
var arr = new Array();
$('#main > a').each(function(i){
arr[i] = this.id;
});
alert('Length:' + arr.length + '\nContent:' + arr.toString());
sunmit();//this is worry~!
}
function sunmit() {
window.location = "http:127.0.0.1:7000//xpas/project/club/a.jsp?Content="+arr.toString());;
}
</script>
</html>
cookieTest.jsp:
<%@page import="java.util.Date"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html >
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>我的购物车</title>
</head>
<body>
<%
Cookie cookies[] = request.getCookies();
String cookieValue1= null;
String cookieValue2 = null;
String cookieValue3 = null;
for (int i = 0; cookies != null && i < cookies.length; i++) {
if (cookies[i].getName().equals("numprice")) {
cookieValue1 = cookies[i].getValue();
}
if(cookies[i].getName().equals("num")){
cookieValue2 = cookies[i].getValue();
}
if(cookies[i].getName().equals("cartid")){
cookieValue3 = cookies[i].getValue();
}
}
out.println("numprice====" + cookieValue1);
out.println("num====" + cookieValue2);
out.println("cartid====" + cookieValue3);
%>
</body>
</html>