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 8014253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:52:35+00:00 2026-06-04T19:52:35+00:00

I have a jetty server running which responds to get requests. If I make

  • 0

I have a jetty server running which responds to get requests. If I make the request using a browser:
localhost:8080/sp or 127.0.0.1:8080/sp
I get the correct data back.

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    response.setContentType("application/json");
response.setStatus(HttpServletResponse.SC_OK);

PrintWriter out = response.getWriter();
out.println("{foobar: true"});
response.flushBuffer();
out.flush();
out.close();
}

but when I try to access the same url using JS the response body is empty.
I’ve tried serving the webpage using both the OS X webserver(port 80) and python SimpleHTTPServer (port 3000).

In both cases the response is empty.

<h1>Single Test Page</h1>

<script>

var httpReq = null;
var url = "http://127.0.0.1:8080/sp";

window.onload = function(){
    var myRequest = new XMLHttpRequest();
    myRequest.open('get', url);
    myRequest.onreadystatechange = function(){
        if ((myRequest.readyState == 4) || (myRequest.status == 200)){
            alert(myRequest.responseText);
        }
    }
    myRequest.send(null);
}

</script>

Could it be an issue with xss attack prevention?
How can I change my setup to use JS to talk to my servlet?
Is there any other way I can make the HTTP get request from JS?

I even added an entry into my /etc/hosts file:
127.0.0.1 foo.com
and changed the JS url to no avail.

  • 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-04T19:52:37+00:00Added an answer on June 4, 2026 at 7:52 pm

    Yes, the problem is that it’s a cross domain request.

    2 possible solutions :

    • use JSONP
    • set CORS headers so that the browser knows it may embed your servlet answer

    Both are easy but the second one has the advantage that you just have to set the headers in the servlet code. For example :

        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Access-Control-Request-Method", "GET");
    

    Another thing : be careful to open your html file in http:// and not file://.

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

Sidebar

Related Questions

I have a basic Jetty server running locally. If I pull up http://localhost/servlet1 in
I have Solr running on my server on localhost in the Jetty container. This
I'd like to have Jetty running on a production server and when I have
We have for all our tests a method which starts a Jetty Server to
I have an existing Java web application running on Linux using embedded Jetty. The
I am running Solr on my windows machine using jetty. I have downloaded the
I have an application which provides services using CXF's Servlet transport and Jetty 6.1.
I have a problem with our Jetty application server. Since yesterday, we have a
I am using mx4j in jetty to have a web console to my jmx
I have a third party server that is periodically sending http post request messages

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.