안드로이드와 mysql을 연동하고 있는 중인데 자꾸 if문이 안먹히네요
jsp 파일 첨부했습니다. ( 아이피는 비공개로 표기하기위해 localhost라 표시했습니다)
-----------------------------java부분 소스 -------------------------------------------
package com.myandoid.medi;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
public class loginActivity extends Activity {
private URLConnection connection;
private HttpURLConnection httpConnection;
private DataOutputStream out = null;
private EditText ID;
private EditText PASS;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
// TODO Auto-generated method stub
Button ok = (Button) findViewById(R.id.ok);
Button cancel = (Button) findViewById(R.id.cancel);
ID = (EditText) findViewById( R.id.IDentry );
PASS = (EditText) findViewById( R.id.PASSentry );
//ID.setInputType(0);
//PASS.setInputType(0);
ok.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if(sending("client_id=" + ID.getText().toString() + "&passwd=" + PASS.getText().toString()).equals("t"))
=======>> 이부분이 안먹히네요 그래서 강제로 If문안에 1의 값을 넣어주면 나머진 다 잘돌아갑니다... 아마 비교부분에서 값이 1의 값이 안나오는 거 같습니다... 수정 부탁드립니다. ㅠㅠ
{
Intent intent = new Intent(getApplicationContext(),mainActivity.class);
intent.putExtra("clientID", ID.getText().toString());
startActivity(intent);
}
else
{
AlertDialog.Builder b = new AlertDialog.Builder(loginActivity.this);
b.setTitle("Error");
b.setMessage("ID/PW를 확인해주세요");
b.setNeutralButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
ID.setText("");
PASS.setText("");
}
});
b.show();
}
}
});
cancel.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
System.exit(0);
}
});
}
String sending( String query )
{
String xmlRt = null;
try {
connection = new URL("http://localhost:9090/login.jsp).openConnection();
httpConnection = (HttpURLConnection)connection;
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setUseCaches(true);
httpConnection.setFollowRedirects(true);
httpConnection.setRequestMethod("POST");
out = new DataOutputStream(connection.getOutputStream());
out.writeBytes(query);
out.flush();
out.close();
connection.connect();
int responseCode = httpConnection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK)
{
InputStream in = httpConnection.getInputStream();
byte buffer[] = new byte[1024];
ByteArrayOutputStream baos = new ByteArrayOutputStream();
while (in.read(buffer, 0, 1024) != -1)
{
baos.write(buffer);
}
xmlRt = new String(baos.toByteArray(), "EUC-KR");
}
} catch (IOException e) {
// TODO Auto-generated catch block
xmlRt = e.toString();
}
return xmlRt.trim();
}
}