安全的Android和Java Dynamic Web App之间的数据传输方式

时间:2016-05-22 15:09:11

标签: java android apache web-services servlets

我正在使用android studio(API 23)开发Android应用程序,我想通过互联网上的Java动态Web应用程序连接我的数据库,其中Apache Tomcat 8用作服务器。我尝试下面的代码,从来没有给出任何错误,但当我运行这个,然后我得到这个错误

错误:任务执行失败':app:dexDebug'。> com.android.ide.common.process.ProcessException:org.gradle.process.internal.ExecException:Process'命令' C:\ Program Files \ Java \ jdk1.8.0_51 \ bin \ java.exe''完成非零退出值2

package app.yog.dev.aems;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;  
import org.apache.http.util.EntityUtils;

import java.io.IOException;
import java.io.UnsupportedEncodingException;


public class LoginActivity extends AppCompatActivity {

public static final String URL="http://10.0.2.2:8080/YSAppAndroid_Login";
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);


    Button loginButton=(Button)findViewById(R.id.btn_login);
    EditText txtUn=(EditText)findViewById(R.id.input_userid);
    EditText txtPwd=(EditText)findViewById(R.id.input_password);

    loginButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            GetXMLTask task = new GetXMLTask();
            task.execute(new String[] { URL });

           // Intent i=new Intent(LoginActivity.this,MainActivity.class);
           // startActivity(i);
        }
    });
}
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) {
        String output = null;
        try {
            DefaultHttpClient httpClient = new DefaultHttpClient();
            HttpGet httpGet = new HttpGet(url);

            HttpResponse httpResponse = httpClient.execute(httpGet);
            HttpEntity httpEntity = httpResponse.getEntity();
            output = EntityUtils.toString(httpEntity);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (ClientProtocolException ex) {
            ex.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return output;
    }

    @Override
    protected void onPostExecute(String output) {
        //Display result on screen or Do Changes in for forward activity
        Intent i=new Intent(LoginActivity.this,MainActivity.class);
        i.putExtra("welcomeName",output);
        startActivity(i);
    }
  }
}

所以我的代码错了,解决方法是什么 提前谢谢....

0 个答案:

没有答案