title: How to solve no 'Access-Control-Allow-Origin' header is present on the requested resource
body: <p><strong>CORS:</strong>
  A very common issue that most of the developers face when they hit a rest service from another domain and so do I.</p>
  
  <p>I get this error : </p>
  
  <p><strong>No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '<a href="http://localhost:8080" rel="nofollow noreferrer">http://localhost:8080</a>' is therefore not allowed access.</strong></p>
  
  <p>Below is the jsp snippet.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;html&gt;
  &lt;head&gt;
  &lt;meta content="text/html; charset=utf-8"&gt;
  &lt;title&gt;AJAX JSON SAMPLE&lt;/title&gt;
  &lt;script type="application/javascript"&gt; 
  function load() 
  { 
     var url = "https://samplewebapp1.herokuapp.com/rest/json/get";//use any url that have json data 
     var request; 
     if(window.XMLHttpRequest){   
      request=new XMLHttpRequest();//for Chrome, mozilla etc 
     }   
     else if(window.ActiveXObject){   
      request=new ActiveXObject("Microsoft.XMLHTTP");//for IE only 
     }   
     request.onreadystatechange  = function(){ 
        if (request.readyState == 4  ) 
        { 
          var jsonObj = JSON.parse(request.responseText);//JSON.parse() returns JSON object 
          document.getElementById("appName").innerHTML =  jsonObj.appName; 
          document.getElementById("language").innerHTML = jsonObj.language; 
        } 
     } 
      request.open("GET", url, true); 
   request.send();  
  } 
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
   appName:
   &lt;span id="appName"&gt;&lt;/span&gt;
   &lt;br /&gt; language:
   &lt;span id="language"&gt;&lt;/span&gt;
   &lt;br /&gt;
   &lt;button type="button" onclick="load()"&gt;Load Information&lt;/button&gt;
  
  &lt;/body&gt;
  
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Below is the rest service implementation of that service.</p>
  
  <pre><code>`package com.heroku.rest;
   import java.util.Date;
   import javax.ws.rs.GET;
   import javax.ws.rs.Path;
   import javax.ws.rs.Produces;
   import javax.ws.rs.core.MediaType;
  
   import com.heroku.model.Heroku;
  
   @Path("/json")
   public class HerokuRestService {
  
   @GET
   @Path("/get")
   @Produces(MediaType.APPLICATION_JSON)
   public Heroku getTrackInJSON() {
           return new Heroku("My First Heroku", "Java", new Date().toString());
      }    }`
  </code></pre>
  
  <p>What am i missing.?</p>