I have a JSP page with some embedded javascript. When the page loads, it tries to detect the presence of a cookie by means of the "if (document.cookie.length > 0)" javascript statement. The strange thing is that, without a cookie present, the "document.cookie.length" statement returns either the number 57, or 55, or 56. If no cookie is present, how is this possible? Furthermore, the statement "document.cookie" returns the following value even when no cookie is present:
"sapj2ee_*=4001;JSESSIONID=ID4001DB0.02315627049120228End".
What is going on?
THe full code is displayed below. The javascript and accompanying body have been tested on a regular html file. I don't understand why it's not working on this jsp page. Any input would be highly appreciated. Thanks
"sapj2ee_*=4001;JSESSIONID=ID4001DB0.02315627049120228End".
What is going on?
THe full code is displayed below. The javascript and accompanying body have been tested on a regular html file. I don't understand why it's not working on this jsp page. Any input would be highly appreciated. Thanks
Code:
<%@ page import="com.sapmarkets.isa.core.util.WebUtil" %>
<%@ taglib uri="/isa" prefix="isa" %>
<isa:contentType/>
<html>
<head>
<title><isa:translate key="b2b.login.jsp.title"/></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
if (document.cookie.length > 0) {
alert(document.cookie.length);
var address;
cookie_data = document.cookie;
alert(cookie_data);
cookie_pieces = cookie_data.split("=");
alert(cookie_pieces);
window.location = cookie_pieces[1];
}
function SetCookie() {
var box = document.form1.region;
var chosen_value = box.options[box.selectedIndex].value;
if (document.form1.remember.checked == true) {
var expiration = new Date("December 1, 2004");
expiration = expiration.toGMTString();
document.cookie = "name=" + chosen_value + ";expires=" + expiration;
}
}
// End -->
</script>
</head>
<body topmargin="0" leftmargin="0" marginheight="0" marginwidth="0">
<form method="post" name="form1" action="javascript:window.location=document.form1.region.options[document.form1.region.selectedIndex].value;" onSubmit="SetCookie();">
<p>Select a region:</p>
<select name="region">
<option value="[URL unfurl="true"]http://www.google.com">Google</option>[/URL]
<option value="[URL unfurl="true"]http://www.yahoo.com">Yahoo</option>[/URL]
<option value="[URL unfurl="true"]http://www.lycos.com">Lycos</option>[/URL]
</select>
<input type="submit" name="Submit" value="Go">
<input type="checkbox" name="remember" value="yes">Remember my selection
</form>
</body>
</html>