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

  • Home
  • SEARCH
  • 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 8651323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:02:19+00:00 2026-06-12T14:02:19+00:00

I am using Apache’s HttpClient to call a servlet from a Java class. I

  • 0

I am using Apache’s HttpClient to call a servlet from a Java class. I want to send an object to the servlet which should save the object using Serialization. How to send the object to the servlet?

public static void main(String[] args) {

        Names names = new Names();
        names.setName("ABC");
        names.setPlace("Bangalore");
        HttpClient httpclient = new DefaultHttpClient();
        HttpGet httpget = new HttpGet("http://localhost:9080/HttpClientPractice/FirstServlet");
//Rest of the code

In the above code snippet, I have another class Names and I want to send an object of Names to the servlet. Right now I am only calling the servlet with the URI, but I want to pass the object.

Thanks!

  • 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-12T14:02:20+00:00Added an answer on June 12, 2026 at 2:02 pm

    Convert the object to a Json String using a Library like Gson in the class you have shown and add this string as a query parameter – showing you how to do it with Gson.

    Gson gson = new Gson();
    String json = gson.toJson(names);
    HttpGet httpget = new HttpGet("http://localhost:9080/HttpClientPractice/FirstServlet?obj="+json);
    

    In the class you are going to store this object, do a fromJson (method in the Gson library)

    Gson gson = new Gson();
    Names names = fromJson(json, Names.class);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Apache HttpClient 4.2.1. Using code copied from the form based login example http://hc.apache.org/httpcomponents-client-ga/examples.html
Using Apache's commons-httpclient for Java, what's the best way to add query parameters to
In using Apache MINA, I'm sending a login request from the client, which is
Using Apache HttpClient 4.1.3 and trying to get the status code from an HttpGet
I'm using Apache Commons FTP to upload a file. Before uploading I want to
I am using apache commons-net for downloading a file from an FTP server. That
I'm using Apache POI to export data to a .xlsx file and I want
I am using Apache Solr via Sunspot on Rails with the standard syntax: class
I am currently using Apache FOP and have a stylesheet (possibly from RenderX) that
When using Apache XML Beans to generate types from xsd:enumeration types, XMLBeans generates custom

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.