title: Jetty embedded HTTP server Access Control Allow Origin
body: <p>I'm embedding a Jetty server within my Java package and I want to query this server through another origin. I currently do not have a web app, this is just a server that I set up to run. I am new to Jetty and would appreciate an explanation as to why the following code is getting the error: <code>XMLHttpRequest cannot load http://localhost:9888/demo/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access.</code></p>
  
  <pre><code>import org.eclipse.jetty.server.Server;
  import org.eclipse.jetty.servlet.ServletContextHandler;
  import org.eclipse.jetty.servlet.ServletHolder;
  
  public class EmbeddingJettyWithServlet {
  
      public static void main(String[] args) throws Exception {
          Server server = new Server(9888);
          ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
          context.setContextPath("/demo");
          server.setHandler(context);
          context.addServlet(new ServletHolder(new MyThriftServlet()), "/*");
          server.start();
      }
  }
  </code></pre>
  
  <p>I've searched online and kept seeing answers like <a href="https://stackoverflow.com/questions/16037558/how-to-add-access-control-allow-origin-to-jetty-server">this</a> where I'm supposed to change WEB-INF/web.xml. But I don't have a WEB-INF folder because this isn't a webapp and the code above is just another class. How do I allow Access-Control-Allow-Origin with this?</p>
  
  <p>Thanks.</p>