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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:40:17+00:00 2026-06-01T15:40:17+00:00

I am trying to have a simple java server respond to an XmlHttpRequest, but

  • 0

I am trying to have a simple java server respond to an XmlHttpRequest, but I am not sure how. As of now, the socket on the server gets the request of the browser. After getting the sockets output stream, the server writes to it, then closes all connections. Is there something more to this? I assume that you would need a header to respond to the request correctly, if so what would that header be. Thanks!

Here is what I am doing right now. I can’t seem to get the browser to accept the message, however.

Edit:
The Java server code:

private String HEADER = "HTTP/1.1 200 OK\n" +
"Cache-Control: private\n" +
"Content-Type: text/html; charset=utf-8\n" +
"Expires: Sun, 21 Feb 2100 20:39:08 GMT\n" +
"Server: Microsoft-IIS/7.5\n" +
"Date: Sun, 21 Apr 2012 20:39:07 GMT\n" +
"Connection: close\n" +
"Content-Length: 10\n";

         browserWriter =
                new PrintWriter(
                        browser.getOutputStream(),true);

            while((data = browserReader.readLine()) != null) {
                if (data.indexOf("POST") != -1) {

                    /* TODO TEST - TAKE OUT */
                    browserWriter.println(HEADER + "APPLESAUSE");
                    browserWriter.close();
                    browserReader.close();
                    browser.close();
                    return;

Javascript:

  xmlhttp.open("POST","http://10.0.2.15:1024/password?url=" + site, false);
  xmlhttp.send(null);
  • 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-01T15:40:19+00:00Added an answer on June 1, 2026 at 3:40 pm

    All XmlHTTPRequest’s require an HTTP response, so HTTP headers are needed. It’s ok to close the connection once the response is given. This is basically just acting as a web server.

    Some HTTP header fields: http://en.wikipedia.org/wiki/List_of_HTTP_header_fields

    See here for the official spec: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

    A decent tutorial here: http://net.tutsplus.com/tutorials/other/http-headers-for-dummies/

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

Sidebar

Related Questions

I'm trying to make a simple chat server in Java. Now I have a
I am trying to adapt my simple socket server so that it can have
I have been trying to call a mapreduce job from a simple java program
I have a simple camera app I'm trying to push to my phone, but
Hi I am trying out a simple java http server NanoHTTPD: http://elonen.iki.fi/code/nanohttpd/ Today I
I have a server application in Java which has two simple operations, addTwoInts and
i am trying to implement a simple server application in java. all it does
I'm trying to have my custom java application use our Active Directory Server for
I am trying to write a simple mail client in Java with sockets. But
I'm trying to write a simple client/server chat application in 2 languages - Java

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.