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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:22:08+00:00 2026-05-31T05:22:08+00:00

I am trying to make an Android/ Java application that needs to connect to

  • 0

I am trying to make an Android/ Java application that needs to connect to a Java EE web service that I will make. I need it to pass in a String, call an action, and scan through a dtabase based on that string, and return a different string back to the java/ android application.

I have it so far being able to send a String to a jsp page and it returning the string. I just need to know how to route the string into an action so I can perform DB queries and such in my web application. Below is what I have so far.

JSP

java.util.Enumeration e = request.getParameterNames();
while (e.hasMoreElements())
{
String pName = (String)e.nextElement();
String pValue = request.getParameter(pName);
String theURL = "index.do"+ "?Parameter1=" + pValue;

//theURL = response.encodeRedirectURL(theURL);

//response.sendRedirect(theURL);
%>

Value :<%=theURL%><%
break;
}

Java Class
import java.net.;
import java.util.
;
import java.io.*;

/**
* An Example of the POST method in HTTP.
*/
public class Main
{

 public static void main (String[] args) throws Exception 
 { 
    // Populate the hashtable with key value pairs of 
    // the parameter name and 
    // value. In this case, we only have the parameter 
    // named "CONTENT" and the 
    // value of CONTENT will be "HELLO JSP !" 

    Hashtable h = new Hashtable(); 
    h.put("CONTENT", "I like stuff"); 
    h.put("ONEMORECONTENT", "HELLO POST !"); 

    // POST it ! 
    String output = POST("xxxxxxxxxxx.jsp", 
                         h); 

    System.out.println(output); 
 } 

/** 
 * The POST method. Accepts 2 parameters 
 * @param targetURL : The URL to POST to. 
 * @param contentHash : The hashtable of the paramters to be posted. 
 *  
 * @return The String returned as a result of POSTing. 
 */ 
public static String POST(String targetURL, Hashtable contentHash) throws Exception 
{     
    URL url; 
    URLConnection conn; 

    // The data streams used to read from and write to the URL connection. 
    DataOutputStream out; 
    DataInputStream in; 

    // String returned as the result of the POST. 
    String returnString = ""; 

    // Create the URL object and make a connection to it. 
    url = new URL (targetURL); 
    conn = url.openConnection(); 

    // Set connection parameters. We need to perform input and output, 
    // so set both as true. 
    conn.setDoInput (true); 
    conn.setDoOutput (true); 

    // Disable use of caches. 
    conn.setUseCaches (false); 

    // Set the content type we are POSTing. We impersonate it as 
    // encoded form data 
    conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); 

    // get the output stream to POST to. 
    out = new DataOutputStream (conn.getOutputStream ()); 
    String content = ""; 

    // Create a single String value to be POSTED from the parameters passed 
    // to us. This is done by making "name"="value" pairs for all the keys 
    // in the Hashtable passed to us. 
    Enumeration e = contentHash.keys(); 
    boolean first = true; 
    while(e.hasMoreElements()) 
    {             
        // For each key and value pair in the hashtable 
        Object key = e.nextElement(); 
        Object value = contentHash.get(key); 

        // If this is not the first key-value pair in the hashtable, 
        // concantenate an "&" sign to the constructed String 
        if(!first)  
            content += "&"; 

        // append to a single string. Encode the value portion 
        content += (String)key + "=" + URLEncoder.encode((String)value); 

        first = false; 
    } 

    // Write out the bytes of the content string to the stream. 
    out.writeBytes (content); 
    out.flush (); 
    out.close (); 

    // Read input from the input stream. 
    in = new DataInputStream (conn.getInputStream ()); 

    String str;         
    while (null != ((str = in.readLine()))) 
    { 
        returnString += str + "\n"; 
    } 

    in.close (); 

    // return the string that was read. 
    return returnString; 
} 

}

OutPut:
Value :index.do?Parameter1=I like stuff

Thanks 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-05-31T05:22:09+00:00Added an answer on May 31, 2026 at 5:22 am

    The simplest way tp solve your problem is to implement a HttpServlet. You can use the client from your example.
    You have to implement doPost(request , response) method.

    You can simply access parameters by calling

    for (String parameterName : request.getParameters()) {
      String value = request.getParameter(parameterName);
      // store parameter values in any structure you need
      ...
    }
    // here you cann access any class from your web application to perform
    // DB operations.
    ...
    // to propagate result to client obtain an OutputStream from response object
    // and simply write data to it
    OutputStream os = response.getOutputStream();
    os.write(your data);
    

    Other way to do the staff is using standard web services. I dont know Android programming but this link seems to show a good example: http://www.ibm.com/developerworks/webservices/library/ws-android/index.html?ca=drs-

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

Sidebar

Related Questions

Trying to make a web service call to an HTTPS endpoint in my Silverlight
trying to make a page which will recursively call a function until a limit
I'm currently trying to develop an android application in eclipse(java) which shows some jokes
Recently started programming Android Java (Eclipse), Im trying to make a simple reader app
I am trying to make an Android app which will pull uploaded videos from
I have a C# application that will need to access files that are on
I am trying to connect Unity with simple Java android development and I actually
I am trying to make an FBconnect application. I got a link http://www.mobisoftinfotech.com/blog/android/845/ From
I am trying to write a simple proxy application on Android in Java to
I am trying to make my application part of android OS, i downloaded the

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.