javascript access denied between jsp applications

P

PromoteDirect

Newsgroups: comp.lang.javascript
Subject: access denied when trying to pass data between jsps
Date: Thu, 09 Mar 2006 10:42:01 -0800

I have two jsp applications. One written with struts and one without.
My struts based application uses window.open to open the first page of
my non-struts application, the user goes through a number of screens
and I then need to copy info from my non struts ap to fields of a form
on my struts ap.

When I was using http://localhost:portnumber/ap/page.jsp
to open http://localhost:portnumber/otherap/page.jsp

and using window.opener.document.forms[0][fieldname] = x
I had no problems.

However when I try to access it from another machine with:
http://computername:portnumber/ap/page.jsp
The page opens but the window.opener.document.forms[0][fieldname] = x
gives a javascript error which says 'access is denied'

Any help would be greatly appreciated
 
P

PromoteDirect

Thanks for that,

Both of my aps run on the same computer - and they are both running on
the same web server. Is there a way I can set the document.domain
attribute to allow the interaction between my pages?
 
T

Thomas 'PointedEars' Lahn

Newsgroups: comp.lang.javascript
Subject: access denied when trying to pass data between jsps
Date: Thu, 09 Mar 2006 10:42:01 -0800

Do not reproduce headers.
[...]
When I was using http://localhost:portnumber/ap/page.jsp
to open http://localhost:portnumber/otherap/page.jsp

and using window.opener.document.forms[0][fieldname] = x
I had no problems.

However when I try to access it from another machine with:
http://computername:portnumber/ap/page.jsp
The page opens but the window.opener.document.forms[0][fieldname] = x
gives a javascript error which says 'access is denied'

Because what happens is that http://computername:portnumber/ap/page.jsp
tries to access http://localhost:portnumber/otherap/page.jsp which is not
allowed as the domains are different (computername != localhost). If you
search the archives for "Same Origin Policy", you will see that not even
document.domain helps you here, as either you do not provide a FQDN for
"computername" (you should always post real addresses if you can), hence
there is no explicit second-level domain, or the second-level domains are
different (your.domain.example != localhost.localdomain).

If you use relative URIs instead, there should not be any problem.
Because, for example, /otherap/page.jsp refers to
http://computername:portnumber/otherap/page.jsp if accessed from
http://computername:portnumber/ap/page.jsp. See RFC3986.


HTH

PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top