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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:59:15+00:00 2026-06-08T02:59:15+00:00

I have setup a java servlet which accepts parameters from the URL and have

  • 0

I have setup a java servlet which accepts parameters from the URL and have it working properly:

public class GetThem extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response)
   throws IOException, ServletException
{
    try {

            double lat=Double.parseDouble(request.getParameter("lat"));
            double lon=Double.parseDouble(request.getParameter("lon"));
            response.setContentType("text/html");
            PrintWriter out = response.getWriter();
            out.println(lat + " and " + lon);

        } catch (Exception e) {

            e.printStackTrace();
    }
  }       
}

So visiting this link:
http://www.example.com:8080/HttpPost/HttpPost?lat=1&lon=2 would output:

  "1.0 and 2.0"

I’m currently calling it from another java program using this code:

try{
            URL objectGet = new URL("http://www.example.com:8080/HttpPost/HttpPost?lat=" + Double.toString(dg.getLatDouble()) + "&lon=" + Double.toString(dg.getLonDouble()));
            URLConnection yc = objectGet.openConnection();
            BufferedReader in = new BufferedReader(
                    new InputStreamReader(
                    yc.getInputStream()));
            in = new BufferedReader(
            new InputStreamReader(
            yc.getInputStream()));
            ...

Now I want to change it so that I’m not using the URL parameters to pass this data to the server. I want to send much larger messages to this server. I am aware that I need to use http post rather than http get to achieve this but am not sure how to do it.

Do I need to change anything on the server side which is receiving data? What do I need to do on the client side which is posting this data?

Any help would be greatly appreciate thanks.
Ideally I’d like to send this data in JSON format.

  • 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-08T02:59:16+00:00Added an answer on June 8, 2026 at 2:59 am

    Below there’s sample from the first link found by “java HTTP POST example” in google.

    try {
        // Construct data
        StringBuilder dataBuilder = new StringBuilder();
        dataBuilder.append(URLEncoder.encode("key1", "UTF-8")).append('=').append(URLEncoder.encode("value1", "UTF-8")).
           append(URLEncoder.encode("key2", "UTF-8")).append('=').append(URLEncoder.encode("value2", "UTF-8"));
    
        // Send data
        URL url = new URL("http://hostname:80/cgi");
        URLConnection conn = url.openConnection();
        conn.setDoOutput(true);
        OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
        wr.write(dataBuilder.toString());
        wr.flush();
    
        // Get the response
        BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        String line;
        while ((line = rd.readLine()) != null) {
            // Process line...
        }
        wr.close();
        rd.close();
    } catch (Exception e) {
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Java class which can be called from shell. (via java [command][options])
I have setup PHP/Java Bridge with working examples in netbeans tomcat directory. What doesnt
I have to setup a basic JAVA application including a GUI based on swing.
Have anyone successfully managed to setup a combined Java/C++ project for Eclipse? What I
I have the following setup: eclipse a standard Java project (A) an eclipse plugin
I was wondering if it's possible to have a java package setup using a
I have netbeans 6.8 with java ME platform setup on my ubuntu 9.10. My
I'd like to setup RMI to pass through port 80 on a java servlet..
I have a simple tomcat servlet application, no Java EE. Also, I am running
I have an environment setup with Java EE (weblogic 10.0). Thus, Kodo/OpenJPA is used

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.