Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8973017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:21:18+00:00 2026-06-15T18:21:18+00:00

I have a simple app (java servlet) hosted on GAE. The app returns json

  • 0

I have a simple app (java servlet) hosted on GAE. The app returns json data. I have set the header info as following in the servlet:

resp.setContentType("application/json");
resp.setHeader("Access-Control-Allow-Origin", "*");
resp.setHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
resp.setHeader("Access-Control-Allow-Credentials", "true");

Here’s the header info when I go to the URL directly on the app engine:

Request Method:GET
Status Code:200 OK
Request Headersview source
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Cache-Control:max-age=0
Connection:keep-alive
Host:---------.appspot.com
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.19 (KHTML, like Gecko)         Chrome/18.0.1025.162 Safari/535.19
Response Headersview source
Access-Control-Allow-Credentials:true
Access-Control-Allow-Methods:GET, POST, OPTIONS
Access-Control-Allow-Origin:*
Cache-Control:private
Content-Encoding:gzip
Content-Length:340
Content-Type:application/json; charset=ISO-8859-1
Date:Sat, 28 Apr 2012 19:14:58 GMT
Server:Google Frontend
Vary:Accept-Encoding

But when I try to access the url from a different domain I get the following response:

Request Method:OPTIONS
Status Code:500 Internal Server Error
Request Headersview source
Accept:*/*
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Access-Control-Request-Headers:origin, x-requested-with, accept
Access-Control-Request-Method:GET
Connection:keep-alive
Host:----------.appspot.com
Origin:http://--------------.com
Referer:http://-------------.com/map/
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.162 Safari/535.19
Response Headersview source
Content-Length:466
Content-Type:text/html; charset=UTF-8
Date:Sat, 28 Apr 2012 19:15:14 GMT
Server:Google Frontend

here is the exact error:

XMLHttpRequest cannot load http://----------.appspot.com/Locations. Origin http://-------------.com is not allowed by Access-Control-Allow-Origin.

The code that tries to access the GAE url looks like this:

$.getJSON("http://---------appspot.com/Locations",function(result){
    for (i=0; i < result.length; i++)

Any help would be much appreciate it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T18:21:19+00:00Added an answer on June 15, 2026 at 6:21 pm

    You need to override standard HttpServlet.doOptions() method to support proper pre-flight request processing.

    @Override
    protected void doOptions(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException 
    { 
        // pre-flight request processing
        resp.setHeader("Access-Control-Allow-Origin", "*");
        resp.setHeader("Access-Control-Allow-Methods", SUPPORTED_METHODS);
        resp.setHeader("Access-Control-Allow-Headers", SUPPORTED_HEADERS);
    }
    
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException 
    {
       resp.setHeader("Access-Control-Allow-Origin", "*");
       resp.setContentType("application/json");
    
       // implementation...
    }
    

    A great article explaining CORS with examples can be found here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have done simple java app for blackberry, while building am getting following error.
I have a simple JSF web app as follows. The Java class contains: private
Right so I have a simple app that consists of a calendar a Set
I have a servlet filter in my Java app to ensure that users are
I have a simple (Servlet, JSP, and JSTL) web app whose main functionality is
I'm developing a simple servlet/JSP, data-driven web site on Google App Engine. I've started
I have simple java app that prints `hello world!' on console. It is packed
I have the following servlet coded in /src/main/java/examples/web/SimpleServlet.java : package examples.web; import java.io.IOException; import
I have simple jsf app with servlet for dynamic images and filter setting utf8
This is a real newbie question. I have simple app that selects a picture

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.