2012-05-07 13 views
0
I have developed android base application and other jsf base web application. 

私のプロジェクトは、アンドロイドアプリケーションからjsfベースのウェブアプリケーションにいくらかの価値を渡す必要があるということです。
私はhttpclientメソッドを使用しています。
値を送信する私のコードはです。は、アンドロイドgpsアプリからjsfウェブアプリケーションに値を送信する

public void loc(double lat,double lon) 
{ 
    String a=String.valueOf(lat); 
    System.out.println("Value of latitude " + lat); 
    Log.d(a, "dfdfdfdfdfdfdfdfdfdfdfdfdddddddddddddd"); 
    System.out.println("Value of longitude " + lon); 



HttpClient client = new DefaultHttpClient(); 
HttpPost post = new HttpPost("http://localhost:8080/q/faces/getLocation.jsp"); 

try { 

    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1); 
    nameValuePairs.add(new BasicNameValuePair("lat", "lat")); 
    nameValuePairs 
      .add(new BasicNameValuePair("lon", "lon")); 
    //nameValuePairs.add(new BasicNameValuePair("accountType", "GOOGLE")); 


    post.setEntity(new UrlEncodedFormEntity(nameValuePairs)); 
    HttpResponse response = client.execute(post); 
    BufferedReader rd = new BufferedReader(new InputStreamReader(
      response.getEntity().getContent())); 

    String line = ""; 
    while ((line = rd.readLine()) != null) { 
     System.out.println(line); 
     if (line.startsWith("Auth=")) { 
      String key = line.substring(5); 
      // Do something with the key 
     } 

    } 
} catch (IOException e) { 
    e.printStackTrace(); 
} 
} 

このコードも機能します。

と私の質問は、どのようにjsfコードからそのような値を取得することです。私が使用している

テクノロジー、

  • JSF
  • アンドロイド

私は値

import org.apache.http.HttpException; 
import org.apache.http.HttpStatus; 
import org.apache.http.client.HttpClient; 
import org.apache.http.impl.client.DefaultHttpClient; 
import java.io.*; 
import org.apache.commons.httpclient.*; 
import org.apache.commons.httpclient.methods.*; 
import org.apache.commons.httpclient.params.HttpMethodParams; 

public class getData { 
private static String url = "http://localhost:8080/q/faces/getdata.jsp"; 

    public String mainm() { 
    // Create an instance of HttpClient. 
    HttpClient client = new HttpClient(); 

    // Create a method instance. 
    GetMethod method = new GetMethod(url); 

    // Provide custom retry handler is necessary 
    method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, 
      new DefaultHttpMethodRetryHandler(3, false)); 

    try { 
     // Execute the method. 
     int statusCode = client.executeMethod(method); 

     if (statusCode != HttpStatus.SC_OK) { 
     System.err.println("Method failed: " + method.getStatusLine()); 
     } 

     // Read the response body. 


    // String result = method.getResponseBodyAsString(); 
    // this is the document returned by the response 
    // System.out.println(result); 
    byte[] responseBody = method.getResponseBody(); 

     // Deal with the response. 
     // Use caution: ensure correct character encoding and is not binary data 
     System.out.println(new String(responseBody)); 

    } catch (HttpException e) { 
    System.err.println("Fatal protocol violation: " + e.getMessage()); 
     e.printStackTrace(); 
    } 
    catch (IOException e) { 
     System.err.println("Fatal transport error: " + e.getMessage()); 
     e.printStackTrace(); 
    } finally { 
     // Release the connection. 
     method.releaseConnection(); 
    } 
    return ""; 
    } 
} 

おかげ

答えて

2
nameValuePairs.add(new BasicNameValuePair("lat", "lat")); 
    nameValuePairs 
      .add(new BasicNameValuePair("lon", "lon")); 
を取得する書き込みコードを持っています

ここでは "lat"とlonは何ですか?それらが何らかの変数であるならば、反転したコマを除去する。このように:

nameValuePairs.add(new BasicNameValuePair("lat", lat)); 
     nameValuePairs 
       .add(new BasicNameValuePair("lon", lon)); 

緯度/経度が何であるか教えてください。この回答を受け入れる場合は右クリックしてください

関連する問題