这是我的demo.jsp页面,我在文本框中输入数据并在cookie中设置该值,但我不知道如何从中检索存储的数据。
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<script>
function validate(){
var input=document.getElementById("txtBX").value;
//alert(input);
setCookie("cookiedata", input);
}
function getCookie(name) {
var start = document.cookie.indexOf( name + "=" );
var len = start + name.length + 1;
if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
return null;
}
if ( start == -1 ) return null;
var end = document.cookie.indexOf( ";", len );
if ( end == -1 ) end = document.cookie.length;
return unescape( document.cookie.substring( len, end ) );
}
function setCookie(name, value) {
var now = new Date();
var time = now.getTime();
time += 3600 * 1000;
now.setTime(time);
document.cookie = name+"=" + value + '; expires=' + now.toUTCString() + ';domain='+window.location.hostname+';path=/';
}
</script>
</head>
<body>
<%
out.println("<table><tr><td>");
out.println("<input type='text' id='txtBX'>");
out.println("<input type='button' value='go'onclick='validate()'>");
%>
</body>
这是我完整的jsp页面,我正在设置cookie,任何人都可以指导我如何将这些cookie作为字符串。