samedi 27 juin 2015

How to reach with JavaScript the services on Tomcat and Apache HTTP?

I use Tomcat based WAR file in a simple web application. This is an HTML input text that passes the data through a java servlet file to read aloud the typed text. I run the application as follows: http://localhost:8080/ServletMavenWebFile-1.0.0-SNAPSHOT/

In addition I have on my website a jQuery load() Method to load data contents of files into a specific element:

$('#content').load("activities/demo_test.php");

I would like to integrate on my website the above WAR file with the apache server (Xampp consist HTML +PHP).

i.e. I wish to load as follows the specified URL but I get an error:

$('#content').load("http://localhost:8080/ServletMavenWebFile-1.0.0-SNAPSHOT/");

XMLHttpRequest cannot load http://localhost:8080/ServletMavenWebFile-1.0.0-SNAPSHOT/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access.

googling for the solution gave me several ways to deal with this:

  • using VirtualHosts
  • using mod_proxy
  • using the method .addHeader("Access-Control-Allow-Origin", "*")
  • etc..

I’m not sure which one is suitable for my case, and also just to get started… how to implement it.

Aucun commentaire:

Enregistrer un commentaire