cookie

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>



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值