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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:18:51+00:00 2026-06-09T19:18:51+00:00

I am submitting JSON data from my GWT-Client and Passing it to my GWT-Server.

  • 0

I am submitting JSON data from my GWT-Client and Passing it to my GWT-Server. And i want to re-submit data to another server and want response from another server to GWT-Client.

I just don’t know how can i do this. I tried below code but not working.

My Code is :

@Override
protected void doPost(HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException {
    System.out.println("POST");

    StringBuffer jb = new StringBuffer();
    URL oracle = new URL("http://www.google.com");

    HttpURLConnection connection = null;
    connection = (HttpURLConnection) oracle.openConnection();
    connection.setRequestMethod("GET");
    connection.setDoOutput(true);
    connection.setDoInput(true);
    request.getInputStream();

    OutputStream wr = connection.getOutputStream();

    InputStream in = request.getInputStream();
    byte[] buffer = new byte[512];
    int read = in.read(buffer, 0, buffer.length);
    while (read >= 0) {
        wr.write(buffer, 0, read);
        read = in.read(buffer, 0, buffer.length);
    }

    wr.flush();
    wr.close();

    BufferedReader in1 = new BufferedReader(new InputStreamReader(
            connection.getInputStream()));
    String inputLine;
    while ((inputLine = in1.readLine()) != null) {
        jb.append(inputLine);
    }
    response.setContentType("text/html");
    // Get the printwriter object from response to write the required json
    // object to the output stream
    PrintWriter out = response.getWriter();
    // Assuming your json object is **jsonObject**, perform the following,
    // it will return your json object
    out.print(jb.toString());
    out.flush();
    in1.close();
}

Please help me.

  • 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-09T19:18:53+00:00Added an answer on June 9, 2026 at 7:18 pm

    You’ll have to send the request to the other server before reading the response

    URL oracle = new URL("http://www.anotherserver.com/");
    
    HttpURLConnection connection = null;
    connection = (HttpURLConnection) oracle.openConnection();
    connection.setRequestMethod("POST");
    connection.setDoOutput(true);
    connection.setDoInput(true);
    
    OutputStream wr = connection.getOutputStream ();
    
    InputStream in = request.getInputStream();
    byte[] buffer = new byte[512]; 
    int read = in.read(buffer,0, buffer.length);
    while (read >= 0) {
       wr.write(buffer,0, read);
       read = in.read(buffer,0,buffer.length);
    }
    
    wr.flush ();
    wr.close ();
    
    
    BufferedReader in = new BufferedReader(new InputStreamReader(
            connection.getInputStream()));
    String inputLine;
    while ((inputLine = in.readLine()) != null) {
        jb.append(inputLine);
    }
    

    see also Using java.net.URLConnection to fire and handle HTTP requests

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

Sidebar

Related Questions

I'm submitting JSON data to a server. The server generates a PDF file and
I am submitting my array from jQuery Datatables for server side processing, in the
I am submitting some form data via ajax and getting back a JSON array
This is the code I have. I want to prevent the form from submitting
Im submitting Data to a php file via AJAX using POST. It worked fine
After trying to format my JSON data by hand in javascript and failing miserably,
My PHP file doing 2 operations: 1. Submits data from form into db table,
I have been successful in returning the json responce from the ajax call to
I'm running XMLHttpRequest request like this: var data = JSON.stringify({ name : 123, id
In jQuery, I'm submitting forms to the server. When there is a validation error,

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.