InVaZ
13 Nov 2005, 08:04 PM
I'm coding a jsp page that checks for cookies and tries to run a javascript function when it detects that a certain cookie exists. I did some debugging and find that the session and cookie and be extracted and displays correctly. However, when I try to test the web page on my browser, the function isn't called and the bottom left displays an error:
Line: 31
Char: 2
Error: Object Expected
Code: 0
My java script codes are as follows:
<script>
function disp_confirm()
{
var choice=confirm("You have an existing bookmark." + '\n' + "Do you want to load it?")
if (choice==true)
{
testwindow = window.open ("<%if(myCookie==null) { out.println(container); } else { out.println(myCookie.getValue()); }%>", "_blank","location=0,status=0,scrollbars=0,width=1020,height=650");
testwindow.moveTo(45,110);
}
else
{
}
}
</script>
The html source file looks like this:
function disp_confirm()
{
var choice=confirm("You have an existing bookmark." + '\n' + "Do you want to load it?")
if (choice==true)
{
testwindow = window.open ("home.jsp
", "_blank","location=0,status=0,scrollbars=0,width=1020,height=650");
testwindow.moveTo(45,110);
}
else
{
}
}
</script>
I believe the error is caused by the line break in the code. However, I do not know how to rectify the problem. Anyone with help is greatly appreciated.
The whole jsp page code for reference:
<%@ page language="java" import="java.util.*"%>
<%
String LoginID = request.getParameter("id");
if(LoginID == null)
{
response.sendRedirect("login.jsp");
}
else
{
session.setAttribute("Current", LoginID);
out.println(LoginID);
out.println(session.getAttribute("Current"));
}
String cookieName = LoginID;
Cookie cookies[] = request.getCookies();
Cookie myCookie = null;
String container = "";
if (cookies != null)
{
for (int i = 0; i < cookies.length; i++)
{
out.println(cookies[i].getValue());
if (cookies [i].getName().equals (cookieName))
{
myCookie = cookies[i];
out.println(myCookie.getValue());
break;
}
}
}
else
{
myCookie = null;
}
%>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>CRIMES-2 Training</title>
<script>
function disp_confirm()
{
var choice=confirm("You have an existing bookmark." + '\n' + "Do you want to load it?")
if (choice==true)
{
testwindow = window.open ("<%if(myCookie==null) { out.println(container); } else { out.println(myCookie.getValue()); }%>", "_blank","location=0,status=0,scrollbars=0,width=1020,height=650");
testwindow.moveTo(45,110);
}
else
{
}
}
</script>
</head>
<% if(myCookie==null)
{
%>
<body bgcolor="#FFFFFF">
<%
}
else
{
%>
<body onload="javascript: disp_confirm()" bgcolor="green">
<% } %>
<!--url's used in the movie-->
<!--text used in the movie-->
<!-- saved from url=(0013)about:internet -->
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="100%" height="100%" id="drag menu2" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="dragmenu.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#000000" /><embed src="dragmenu.swf" quality="high" bgcolor="#000000" width="800" height="600" name="drag menu2" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
</body>
</html>
Line: 31
Char: 2
Error: Object Expected
Code: 0
My java script codes are as follows:
<script>
function disp_confirm()
{
var choice=confirm("You have an existing bookmark." + '\n' + "Do you want to load it?")
if (choice==true)
{
testwindow = window.open ("<%if(myCookie==null) { out.println(container); } else { out.println(myCookie.getValue()); }%>", "_blank","location=0,status=0,scrollbars=0,width=1020,height=650");
testwindow.moveTo(45,110);
}
else
{
}
}
</script>
The html source file looks like this:
function disp_confirm()
{
var choice=confirm("You have an existing bookmark." + '\n' + "Do you want to load it?")
if (choice==true)
{
testwindow = window.open ("home.jsp
", "_blank","location=0,status=0,scrollbars=0,width=1020,height=650");
testwindow.moveTo(45,110);
}
else
{
}
}
</script>
I believe the error is caused by the line break in the code. However, I do not know how to rectify the problem. Anyone with help is greatly appreciated.
The whole jsp page code for reference:
<%@ page language="java" import="java.util.*"%>
<%
String LoginID = request.getParameter("id");
if(LoginID == null)
{
response.sendRedirect("login.jsp");
}
else
{
session.setAttribute("Current", LoginID);
out.println(LoginID);
out.println(session.getAttribute("Current"));
}
String cookieName = LoginID;
Cookie cookies[] = request.getCookies();
Cookie myCookie = null;
String container = "";
if (cookies != null)
{
for (int i = 0; i < cookies.length; i++)
{
out.println(cookies[i].getValue());
if (cookies [i].getName().equals (cookieName))
{
myCookie = cookies[i];
out.println(myCookie.getValue());
break;
}
}
}
else
{
myCookie = null;
}
%>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>CRIMES-2 Training</title>
<script>
function disp_confirm()
{
var choice=confirm("You have an existing bookmark." + '\n' + "Do you want to load it?")
if (choice==true)
{
testwindow = window.open ("<%if(myCookie==null) { out.println(container); } else { out.println(myCookie.getValue()); }%>", "_blank","location=0,status=0,scrollbars=0,width=1020,height=650");
testwindow.moveTo(45,110);
}
else
{
}
}
</script>
</head>
<% if(myCookie==null)
{
%>
<body bgcolor="#FFFFFF">
<%
}
else
{
%>
<body onload="javascript: disp_confirm()" bgcolor="green">
<% } %>
<!--url's used in the movie-->
<!--text used in the movie-->
<!-- saved from url=(0013)about:internet -->
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="100%" height="100%" id="drag menu2" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="dragmenu.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#000000" /><embed src="dragmenu.swf" quality="high" bgcolor="#000000" width="800" height="600" name="drag menu2" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
</body>
</html>