#xmltest.php

<?

echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>";

echo "<result>";

if($_GET["id"] && $_GET["pwd"]){

$connect = mysql_connect("localhost","root","apmsetup");

mysql_query("set names utf8");

mysql_select_db("mydb",$connect);

$sql = "select * from student where id =".$_GET["id"]." and pwd=".$_GET["pwd"];

$result = mysql_query($sql);

$num = @mysql_num_rows($result);


if($num){

$row = mysql_fetch_array($result);

?>

<date><?=date("Y-m-d")?></date>

<name><?=$row[name]?></name>

<phone><?=$row[phone]?></phone>

<address><?=$row[address]?></address>

<path><?=$_SERVER["PHP_SELF"]?></path>

<ip><?=$_SERVER["REMOTE_ADDR"]?></ip>

<? } else {

echo "<error> id or password is not matched</error>";

}

} else {

echo "<error>request page error</error>";

}

echo "</result>";

?>

#MainActivity.java

package com.example.s08;


import java.io.BufferedReader;

import java.io.InputStreamReader;

import java.net.HttpURLConnection;

import java.net.URL;


import org.xmlpull.v1.XmlPullParser;

import org.xmlpull.v1.XmlPullParserFactory;


import android.os.Bundle;

import android.app.Activity;

import android.util.Log;

import android.view.Menu;

import android.view.View;

import android.widget.Button;

import android.widget.EditText;

import android.widget.TextView;

import android.widget.Toast;


public class MainActivity extends Activity {

TextView tv_message;

EditText edt_id, edt_password;

Button btn_cfn;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

tv_message = (TextView)findViewById(R.id.tv_message);

edt_id = (EditText)findViewById(R.id.edt_id);

edt_password = (EditText)findViewById(R.id.edt_password);

btn_cfn = (Button)findViewById(R.id.btn_cfn);

btn_cfn.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View arg0) {

// TODO Auto-generated method stub

if(edt_id.getText().toString().equals("")){

Toast.makeText(MainActivity.this, "아이디를 입력하세요!", Toast.LENGTH_LONG).show();

return;

}

if(edt_password.getText().toString().equals("")) {

Toast.makeText(MainActivity.this, "비밀번호를 입력하세요!", Toast.LENGTH_LONG).show();

return;

}

tv_message.setText("");

String id = edt_id.getText().toString();

String pwd = edt_password.getText().toString();

URL url = null;


try {

url = new URL("http://220.69.130.192/xmltest.php?id="+id+"&pwd="+pwd);

XmlPullParserFactory fac = XmlPullParserFactory.newInstance();

XmlPullParser parser = fac.newPullParser();

parser.setInput(url.openStream(),"utf-8");

String tag = "";

int eventType = parser.getEventType();

while(eventType != XmlPullParser.END_DOCUMENT){

switch(eventType){

case XmlPullParser.START_DOCUMENT:break;

case XmlPullParser.START_TAG: tag = parser.getName(); break;

case XmlPullParser.TEXT:

if(tag.equals("date")) tv_message.append("date: "+parser.getText()+"\n");

else if(tag.equals("name")) tv_message.append("name:"+parser.getText()+"\n");

else if(tag.equals("phone")) tv_message.append("phone:"+parser.getText()+"\n");

else if(tag.equals("address")) tv_message.append("address:"+parser.getText()+"\n");

else if(tag.equals("path")) tv_message.append("path: "+parser.getText()+"\n");

else if(tag.equals("ip")) tv_message.append("ip: "+parser.getText()+"\n");

else if(tag.equals("error")) tv_message.append("error"+parser.getText()+"\n");

break;

case XmlPullParser.END_TAG: tag=""; break;

case XmlPullParser.END_DOCUMENT: break;

}

eventType = parser.next();

}

} catch (Exception e) {

Log.i("web","오류 :" + e);

}

}

});

}


@Override

public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present.

getMenuInflater().inflate(R.menu.main, menu);

return true;

}


}







'이전것 > 개발' 카테고리의 다른 글

PLM -> 3d Experience Platform Install  (0) 2016.07.11
android -> intent  (0) 2016.07.08
android -> Server -> android  (0) 2016.07.08
android -> webServer  (0) 2016.07.08
android -> webView  (0) 2016.07.07
블로그 이미지

잉비니

,