• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ItemXMLHttp is working with plain HTML page but not with JSP

 
Rana Dey
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a JSP page hosted on tomcat and calls a web interface (webservice hosted on some other server) from javascript but it gives access denied issue.

However, when we use same JavaScript code which calls the webservice in a plain HTML page, it works. I am still unable to locate the problem, please help.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64715
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the time a JSP page gets to the browser, it's just an HTML page like any other. So you can get the markup of the non-working page (View Source from browser), and compare it to the markup of the working page to see what's different.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64715
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
P.S. Access denied usually means you are trying to make a cross-domain request, which is not allowed.
 
Rana Dey
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code is the same javascript code but one is with plain HTML (not hosted on tomcat) and other is with JSP page. The later one is not working.

But in general, a webservice will always be hosted on some remote server and possibly placed on a different domain. The client JSP page will however work on local domain.

Regards,
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64715
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code is the same javascript code but one is with plain HTML (not hosted on tomcat) and other is with JSP page.


Again, the fact that one page is a JSP is irrelevant. The browser has no knowledge that the HTML was generated on the server by JSP. If the JavaScript is identical on the pages, then they would both work. So there must be a difference at the browser.

And again, you can;t make an Ajax request to a domain other then that which served the page. You'll need to use a server-side proxy, or JSONP if all you are making are GET requests.
 
Rana Dey
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can;t make an Ajax request to a domain other then that which served the page.


In this case even the port needs to be same?? for eg. if the page on browser has been fetched from http://ip:8080/, then the other request for http://ip:8443/ is also subject to cross domain issue??

Regards
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64715
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happened when you tried it?
 
Rana Dey
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I received access denied.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64715
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question answered.
 
Rana Dey
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
just to add, when we are trying to access the webservice (from Javascript) through HTTPS, its showing error as Access denied. But when we are accessing the same webservice (from Javascript) through HTTP, its working.

The above behavior is with JSP implementation running on Tomcat (not the standalone html page). SO, I suspect is it really the cross domain issue as you pointed.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic