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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:06:48+00:00 2026-06-18T02:06:48+00:00

Im trying to send some parameters from a simple android app using AsyncTask<> through

  • 0

Im trying to send some parameters from a simple android app using AsyncTask<>
through a get request ,but when i get the parameters on the servlet those are null!
And i cant understand why… , logcat doesnt show any errors so i cant find why..
here is my main activity :

package com.theopentutorials.android;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

//the main activity
public class HttpGetServletActivity extends Activity implements OnClickListener {
Button button; // gui part
TextView outputText;
EditText titulli;
EditText ingredientet;
EditText receta;

public static String getTitulliS() {
    return titulliS;
}

// setters and getters of the url parameters
public static void setTitulliS(String titulliS) {
    HttpGetServletActivity.titulliS = titulliS;
}

public static String getIngredientetS() {
    return ingredientetS;
}

public static void setIngredientetS(String ingredientetS) {
    HttpGetServletActivity.ingredientetS = ingredientetS;
}

public static String getRecetaS() {
    return recetaS;
}

public static void setRecetaS(String recetaS) {
    HttpGetServletActivity.recetaS = recetaS;
}

public static String getURL() {
    return URL;
}

public static void setURL(String uRL) {
    URL = uRL;
}

// the parameters i would like to send
static String titulliS;
static String ingredientetS;
static String recetaS;
static String URL = "http://10.0.2.2:8080/HttpGetServlet/HelloWorldServlet?"
        + getTitulliS() + getIngredientetS() + getRecetaS();

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    findViewsById();

    button.setOnClickListener(this);
}

private void findViewsById() {
    button = (Button) findViewById(R.id.button);
    outputText = (TextView) findViewById(R.id.outputTxt);
    titulli = (EditText) findViewById(R.id.editText1);
    ingredientet = (EditText) findViewById(R.id.editText2);
    receta = (EditText) findViewById(R.id.editText2);
    setTitulliS("titulli=" + titulli.getText().toString() + "&");
    setIngredientetS("ingredientet=" + ingredientet.getText().toString()
            + "&");
    setRecetaS("receta=" + receta.getText().toString());

}

public void onClick(View view) {

    GetXMLTask task = new GetXMLTask();
    task.execute(new String[] { URL });
}

private class GetXMLTask extends AsyncTask<String, Void, String> {
    @Override
    protected String doInBackground(String... urls) {
        String output = null;
        for (String url : urls) {
            output = getOutputFromUrl(url);
        }
        return output;
    }

    private String getOutputFromUrl(String url) {
        StringBuffer output = new StringBuffer("");
        try {
            InputStream stream = getHttpConnection(url);
            BufferedReader buffer = new BufferedReader(
                    new InputStreamReader(stream));
            String s = "";
            while ((s = buffer.readLine()) != null)
                output.append(s);
        } catch (IOException e1) {
            e1.printStackTrace();
        }
        return output.toString();
    }

    // Makes HttpURLConnection and returns InputStream
    private InputStream getHttpConnection(String urlString)
            throws IOException {
        InputStream stream = null;
        URL url = new URL(urlString);
        URLConnection connection = url.openConnection();

        try {
            HttpURLConnection httpConnection = (HttpURLConnection) connection;
            httpConnection.setRequestMethod("GET");
            httpConnection.connect();

            if (httpConnection.getResponseCode() == HttpURLConnection.HTTP_OK) {
                stream = httpConnection.getInputStream();
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return stream;
    }

    @Override
    protected void onPostExecute(String output) {
        outputText.setText(output);
    }
}
}

and here is my simple servlet :

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/HelloWorldServlet")
public class HelloWorldServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

public HelloWorldServlet() {
    super();
}

protected void doGet(HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException {
       String titulli =  request.getParameter("titulli");
      String ingredientet =  request.getParameter("ingredientet");
       String receta =  request.getParameter("receta");
        PrintWriter out = response.getWriter();
        out.println(titulli+ingredientet+receta);
        System.out.println(titulli+ingredientet+receta);
}
}

Does somebody have any idea?Thank you in advance !

  • 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-18T02:06:49+00:00Added an answer on June 18, 2026 at 2:06 am

    To me, it looks as if you are setting up the parameter extension for the input fields only in onCreate(), when you would really have to do this in onClick() for example.

    I’d have a few other remarks along the lines of “why static?” etc but you didn’t ask for that. 😉

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

Sidebar

Related Questions

I'm trying to send a URL with some parameters using HttpPost but it has
I am trying to send some text in an email from my cocoa app
I am currently trying to send some data from and Android application to a
I am trying to send some simple mouse down/up messages to Windows Calculator using
I am trying to send a GET via Android's HttpURLConnection (imported from org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection ),
I am trying to get a Android device to send some information to a
I'm trying to send 2 parameter from one activity to another,but for some reason
Trying to send some email in my C# app. I am behind a proxy
I'm trying to send some information to our CRM from a form on our
I'm trying to share some text using an intent: Intent i = new Intent(android.content.Intent.ACTION_SEND);

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.