T
tungchau81
Hi everybody,
In MainPage.jsp, I had simple code to redirect it to a page called
'http://123.123.123.123' . However, I want to bypass the login page
(http://123.123.123.123/login.htm) by setting cookie of authorization
token, so that it will point directly to
http://123.123.123.123/main.htm. Here is my code:
++++++++++++++++++++++++++++++++++++++++++++++++
<html>
<head>
<title></title>
var djConfig = {isDebug: true, debugAtAllCosts : true};
</script>
dojo.require("dojo.io");
dojo.require("dojo.io.cookie");
dojo.hostenv.writeIncludes();
</script>
function main() {
if (dojo.io.cookie.isSupported() == true) {
dojo.io.cookie.setCookie('xxx', 'yyy', null, null, null,
null);
var cookieValue = dojo.io.cookie.getCookie('xxx');
alert(cookieValue);
}
document.location = 'http://123.123.123.123';
}
</script>
</head>
<body onload="main();"></body>
</html>
++++++++++++++++++++++++++++++++++++++++++++++++++
alert(cookieValue) returns the correct value of the cookie. However, I
still can not bypass the login page.
I also tried the following approach, but then, alert(cookieValue)
returns null.
+++++++++++++++++++++++++++++++++++++++
dojo.io.cookie.setCookie('xxx', 'yyy', 90, '/', '123.123.123.123',
false);
var cookieValue = dojo.io.cookie.getCookie('xxx');
alert(cookieValue); /_/***returns null
++++++++++++++++++++++++++++++++++++++++
My MainPage.jsp was the result of a webwork action which is similar to
Struts action.
Is there anything I m doing wrong here? I am really stuck and do not
know what other approaches I should try. Any advice is greatly
appreciated.
P.S.: Here is the code of setCookie and getCookie in dojo library for
your preference:
dojo.io.cookie.setCookie = function(name, value, days, path, domain,
secure) {
var expires = -1;
if(typeof days == "number" && days >= 0) {
var d = new Date();
d.setTime(d.getTime()+(days*24*60*60*1000));
expires = d.toGMTString();
}
value = escape(value);
document.cookie = name + "=" + value + ";"
+ (expires != -1 ? " expires=" + expires + ";" : "")
+ (path ? "path=" + path : "")
+ (domain ? "; domain=" + domain : "")
+ (secure ? "; secure" : "");
}
dojo.io.cookie.set = dojo.io.cookie.setCookie;
dojo.io.cookie.getCookie = function(name) {
// FIXME: Which cookie should we return?
// If there are cookies set for different sub domains in the
current
// scope there could be more than one cookie with the same
name.
// I think taking the last one in the list takes the one from
the
// deepest subdomain, which is what we're doing here.
var idx = document.cookie.lastIndexOf(name+'=');
if(idx == -1) { return null; }
var value = document.cookie.substring(idx+name.length+1);
var end = value.indexOf(';');
if(end == -1) { end = value.length; }
value = value.substring(0, end);
value = unescape(value);
return value;
}
dojo.io.cookie.get = dojo.io.cookie.getCookie;
Tung Chau
In MainPage.jsp, I had simple code to redirect it to a page called
'http://123.123.123.123' . However, I want to bypass the login page
(http://123.123.123.123/login.htm) by setting cookie of authorization
token, so that it will point directly to
http://123.123.123.123/main.htm. Here is my code:
++++++++++++++++++++++++++++++++++++++++++++++++
<html>
<head>
<title></title>
var djConfig = {isDebug: true, debugAtAllCosts : true};
</script>
dojo.require("dojo.io");
dojo.require("dojo.io.cookie");
dojo.hostenv.writeIncludes();
</script>
function main() {
if (dojo.io.cookie.isSupported() == true) {
dojo.io.cookie.setCookie('xxx', 'yyy', null, null, null,
null);
var cookieValue = dojo.io.cookie.getCookie('xxx');
alert(cookieValue);
}
document.location = 'http://123.123.123.123';
}
</script>
</head>
<body onload="main();"></body>
</html>
++++++++++++++++++++++++++++++++++++++++++++++++++
alert(cookieValue) returns the correct value of the cookie. However, I
still can not bypass the login page.
I also tried the following approach, but then, alert(cookieValue)
returns null.
+++++++++++++++++++++++++++++++++++++++
dojo.io.cookie.setCookie('xxx', 'yyy', 90, '/', '123.123.123.123',
false);
var cookieValue = dojo.io.cookie.getCookie('xxx');
alert(cookieValue); /_/***returns null
++++++++++++++++++++++++++++++++++++++++
My MainPage.jsp was the result of a webwork action which is similar to
Struts action.
Is there anything I m doing wrong here? I am really stuck and do not
know what other approaches I should try. Any advice is greatly
appreciated.
P.S.: Here is the code of setCookie and getCookie in dojo library for
your preference:
dojo.io.cookie.setCookie = function(name, value, days, path, domain,
secure) {
var expires = -1;
if(typeof days == "number" && days >= 0) {
var d = new Date();
d.setTime(d.getTime()+(days*24*60*60*1000));
expires = d.toGMTString();
}
value = escape(value);
document.cookie = name + "=" + value + ";"
+ (expires != -1 ? " expires=" + expires + ";" : "")
+ (path ? "path=" + path : "")
+ (domain ? "; domain=" + domain : "")
+ (secure ? "; secure" : "");
}
dojo.io.cookie.set = dojo.io.cookie.setCookie;
dojo.io.cookie.getCookie = function(name) {
// FIXME: Which cookie should we return?
// If there are cookies set for different sub domains in the
current
// scope there could be more than one cookie with the same
name.
// I think taking the last one in the list takes the one from
the
// deepest subdomain, which is what we're doing here.
var idx = document.cookie.lastIndexOf(name+'=');
if(idx == -1) { return null; }
var value = document.cookie.substring(idx+name.length+1);
var end = value.indexOf(';');
if(end == -1) { end = value.length; }
value = value.substring(0, end);
value = unescape(value);
return value;
}
dojo.io.cookie.get = dojo.io.cookie.getCookie;
Tung Chau