Let me see if I've got this straight. The JavaScript is trying to create the cookie *in the browser.* The server has nothing to do with it (except to read the cookie contents, presumably). If you are setting cookies in the server, it has to happen before any HTML is output by the jsp.

The only thing that jumps out at me below is your "path" value. "Path" is not a hostname or IP address, but is a URL path-prefix *within* the host. I typically use "path=/", so that the cookie will be sent along with a request for any URL in the domain to which the cookie will be sent. If you want to limit the cookie to a particular domain you should set the domain attribute, not the path attribute.

See http://www.csc.flint.umich.edu/~hickslm/392/JavaScript/jumpingJS/cookies/BillDortchSripts.htm for some useful cookie handling functions.

=Spencer

Luc Foisy wrote:

Now that we established that JavaScript != Java, i thought I'd come ask a JavaScript question here, but really for lack of knowing any better place to go.

Running under tomcat with jsp pages, trying to create cookies, but they dont even seem to be made. I was wondering if anyone could point out something I am missing here.

Here is the jsp page in part

logon.jsp:
<HTML>
<HEAD>
<meta http-equiv="content-type" content="text/html;charset=ISO-8859-1">
<TITLE>ICRM</TITLE>
<SCRIPT SRC="commonscript.js"></SCRIPT>
<jsp:include page="style.inc" flush="true"/>
</HEAD>
<%
if( request.getParameter("type").equals("role") )
{
%>
<BODY BGCOLOR="#F0FFFF" ONLOAD="loadRoleLogonPage()">
<%
}
else
{
%>
<BODY BGCOLOR="#F0FFFF" ONLOAD="loadContactLogonPage()">
<%
}
%>
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" WIDTH="100%" HEIGHT="100%"> <TR>
<TD ALIGN="left" VALIGN="top" HEIGHT="139" WIDTH="142">
<IMG SRC="images\logo.gif" HEIGHT="139" WIDTH="142">
</TD>
<TD ALIGN="left" VALIGN="top">
<IMG SRC="images\title1.jpg"><IMG SRC="images\title.jpg" >
</TD>
</TR>
<TR>
<TD ALIGN="left" VALIGN="top" COLSPAN="2">

<FORM NAME="logincheck" METHOD="post" ACTION="login_check.jsp?type=<%=request.getParameter("type")%>">
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" WIDTH="640">
<TR>
<TD WIDTH="20">
Email:
</TD>
<TD>
<INPUT TYPE="text" NAME="email" SIZE="30" MAXLENGTH="50">
</TD>
</TR>
<TR>
<TD WIDTH="20">
Password:
</TD>
<TD>
<INPUT TYPE="password" NAME="password" SIZE="30" MAXLENGTH="50"><BR>
</TD>
</TR>
<%
if( request.getParameter("type").equals("role") )
{
%>
<TR>
<TD WIDTH="20">
Role:
</TD>
<TD>
<%= TMHTTPLibrary.instance().recordSet2PickList(ICRMWebApp.getRoleRecordSet(),"roleid",false) %>
</TD>
</TR>
<%
}
%>
<TR>
<TD WIDTH="20" ALIGN="right">
<INPUT TYPE="checkbox" CHECKED NAME="rememberlogon">
</TD>
<TD>
Remember Logon Information
</TD>
</TR>
<TR>
<TD COLSPAN="2">
<%
if( request.getParameter("type").equals("role") )
{
%>
<INPUT TYPE="image" ALT="Logon" VALUE="Logon" NAME="logon" SRC="images\logon.jpg" WIDTH="140" HEIGHT="27" ALIGN="top" BORDER="0" ONCLICK="saveRoleLogon()">
<%
}
else
{
%>
<INPUT TYPE="image" ALT="Logon" VALUE="Logon" NAME="logon" SRC="images\logon.jpg" WIDTH="140" HEIGHT="27" ALIGN="top" BORDER="0" ONCLICK="saveContactLogon()")>
<%
}
%>
</TD>
</TR>
</TABLE>
</FORM>


Here is commonscript.js

function loadRoleLogonPage()
{
document.logincheck.email.value=readEmbeddedCookie("icrmrolelogon","email");
document.logincheck.password.value=readEmbeddedCookie("icrmrolelogon","password");
document.logincheck.roleid.value=readEmbeddedCookie("icrmrolelogon","roleid");
}

function loadContactLogonPage()
{
document.logincheck.email.value=readEmbeddedCookie("icrmcontactlogon","email");
document.logincheck.password.value=readEmbeddedCookie("icrmcontactlogon","password");
}

function saveRoleLogon()
{
if( document.logincheck.rememberlogon.checked )
{
writeEmbeddedCookie("icrmrolelogon","email",document.logincheck.email.value);
writeEmbeddedCookie("icrmrolelogon","password",document.logincheck.password.value);
writeEmbeddedCookie("icrmrolelogon","roleid",document.logincheck.roleid.value);
}
}

function saveContactLogon()
{
if( document.logincheck.rememberlogon.checked )
{
writeEmbeddedCookie("icrmcontactlogon","email",document.logincheck.email.value);
writeEmbeddedCookie("icrmcontactlogon","password",document.logincheck.password.value);
}
}

function readEmbeddedCookie(cookieName,itemToRead)
{
var temp = getCookieValue(cookieName) + ";";
var Pos = temp.indexOf("=",temp.indexOf(itemToRead + "="));
if (temp.indexOf(itemToRead + "=") == -1) return "";
return unescape(temp.substring(Pos + 1,temp.indexOf(";",Pos)));
}

function getCookieValue(name)
{
var temp = document.cookie + ";";
var Pos = temp.indexOf("=",temp.indexOf(name + "="));
if (temp.indexOf(name + "=") == -1) return "";
return unescape(temp.substring(Pos + 1,temp.indexOf(";",Pos)));
}

function writeEmbeddedCookie(cookieName,itemToWrite,valueToWrite)
{
var temp = getCookieValue(cookieName) + ";";
var Pos = temp.indexOf(itemToWrite + "=");
if (Pos > 0)
{
var beginningOfBlock = temp.substring(0,Pos);
var endOfBlock = temp.substring(temp.indexOf(";",Pos + itemToWrite.length) + 1,temp.length);
}
else if (Pos == 0)
{
beginningOfBlock = "";
var endOfBlock = temp.substring(temp.indexOf(";",Pos + itemToWrite.length) + 1,temp.length);
}
else
{
beginningOfBlock = "";
endOfBlock = temp;
}
temp = beginningOfBlock + itemToWrite + "=" + escape(valueToWrite) + ";" + endOfBlock;
temp = temp.substring(0,temp.length - 1);
writeCookie("172.16.0.222",2000,cookieName,temp );
}

function altSetCookie(name,value,expires,path)
{
document.cookie = name + "=" + escape (value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "");
}

function writeCookie(cookiePath,daysToExpire,name,contents)
{
if (contents != getCookieValue(name))
{
if (contents != "")
{
var ExpireDate= new Date();
ExpireDate.setTime(ExpireDate.getTime() + (daysToExpire * 24 * 3600 * 1000));
altSetCookie(name,contents,ExpireDate,"172.16.0.222");
}
}
}


____________________________________________________
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm

Be respectful! Clean up your posts before replying
____________________________________________________


____________________________________________________
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm

Be respectful! Clean up your posts before replying
____________________________________________________

Reply via email to