app提交信息到PC端mysql数据库

新建名为SignActivity

package com.example.administrator.success;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText; public class SignActivity extends Activity {
private EditText name;
// private EditText password;
private Button signup;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sign);
name=(EditText) findViewById(R.id.etSgAccount);
// password=(EditText) findViewById(R.id.etSgPassword);
signup=(Button) findViewById(R.id.btnSign);
}
/*发起HTTP请求*/
public void onLogin(View v)
{
String url="http://182.92.66.60:8083/saveTestApp.jsp";
new HttpThread(url, name.getText().toString()).start();
} }

HttpThread

package com.example.administrator.success;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL; import android.R.string; public class HttpThread extends Thread {
String url;
String name;
// String password; public HttpThread(String url, String name) {
// TODO Auto-generated constructor stub
this.url = url;
this.name = name;
// this.password = password;
} private void doGet() throws IOException {
/*将username和password传给Tomcat服务器*/
url=url+"?name="+name;
try {
URL httpUrl = new URL(url);
/*获取网络连接*/
HttpURLConnection conn = (HttpURLConnection) httpUrl.openConnection();
/*设置请求方法为GET方法*/
conn.setRequestMethod("GET");
/*设置访问超时时间*/
conn.setReadTimeout(5000);
BufferedReader reader=new BufferedReader(new InputStreamReader(conn.getInputStream()));
String str;
StringBuffer sb=new StringBuffer();
//读取服务器返回的信息
while((str=reader.readLine())!=null)
{
sb.append(str);
}
//把服务端返回的数据打印出来
System.out.println("result"+sb.toString());
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} } /*在run中调用doGet*/
@Override
public void run() {
try {
doGet();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

布局文件activity_sign.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true"
android:background="#ff6699cc"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" > <RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#fffffffb"
android:orientation="horizontal"
android:padding="40dp" > <EditText
android:id="@+id/etSgAccount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_marginBottom="20dp"
android:hint="Account"
android:inputType="textEmailAddress" /> <EditText
android:id="@+id/etSgPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/etSgAccount"
android:layout_marginBottom="20dp"
android:hint="Password"
android:inputType="textPassword" />
<EditText
android:id="@+id/etSgRePassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/etSgPassword"
android:layout_marginBottom="20dp"
android:hint="repassword"
android:inputType="textPassword" /> <Button
android:id="@+id/btnSign"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/etSgRePassword"
android:background="#ff6699cc"
android:onClick="onLogin"
android:text="signup"
android:textColor="#ffffffff"
android:textSize="24sp" />
</RelativeLayout> </LinearLayout>

自己搭一个Tomact服务器,把SignActivity里的url换成自己的就OK了

Android app与PC端交互的更多相关文章

  1. Android客户端与服务端交互之登陆示例

    Android客户端与服务端交互之登陆示例 今天了解了一下android客户端与服务端是怎样交互的,发现其实跟web有点类似吧,然后网上找了大神的登陆示例,是基于IntentService的 1.后台 ...

  2. 我的Android进阶之旅------>Android实现用Android手机控制PC端的关机和重启的功能(三)Android客户端功能实现

    我的Android进阶之旅------>Android实现用Android手机控制PC端的关机和重启的功能(一)PC服务器端(地址:http://blog.csdn.net/ouyang_pen ...

  3. android中的HttpURLConnection和HttpClient实现app与pc数据交互

    自学android的这几天很辛苦,但是很满足,因为每当学到一点点知识点都会觉得很开心,觉得今天是特别有意义的,可能这个就是一种莫名的热爱吧. 下面来说说今天学习的HttpURLConnection和H ...

  4. android客户端app和服务端交互token的作用

    Android客户端和服务端如何使用Token和Session niceheart关注1人评论34644人阅读2014-09-16 16:38:44   对于初学者来说,对Token和Session的 ...

  5. JS判断android ios系统 PC端和移动端

    最近公司上线移动端,需要根据不同的系统跳转到不同的产品页面,百度后发现这一段代码很好用,不但可以判断当前是什么系统,还能知道当前浏览器是什么内核,移动端PC端都已测试无问题! var browser ...

  6. 我的Android进阶之旅------&gt;Android实现用Android手机控制PC端的关机和重新启动的功能(二)Androidclient功能展示

    Androidclient的实现思路大致例如以下: 1.首先扫描局域网内全部PC,看是否有PC端的server在执行并监听30000port. watermark/2/text/aHR0cDovL2J ...

  7. Android App之间通过Intent交互

    Android 最重要的功能之一是应用能够基于它要执行的"操作"向另一个应用发送用户. 例如,如果您的应用有您要在地图上显示的公司地址,您无需在显示地图的应用中构建 Activit ...

  8. PC/APP/H5三端测试的相同与不同

    随着手机应用的不断状态,同一款产品的移动端应用市场占相较PC端也越来越大,那么app与PC端针对这些产品的测试有什么相同与不同之处呢?总结如下: 首先谈一谈相同之处: 一,针对同一个系统功能的测试,三 ...

  9. Android App常规测试内容

    转自:https://mp.weixin.qq.com/s?__biz=MzU0NjcyNDg3Mw==&mid=2247484053&idx=1&sn=116fe8c7eed ...

随机推荐

  1. 高速排序java语言实现

    本博客不再更新,很多其它精彩内容请訪问我的独立博客 高速排序是非常重要的排序算法,可是我在学的时候发现网上没有特别好的样例所以自己动手写了一个. 自己动手丰衣足食. package sort; imp ...

  2. mongo: 删

    删除:remove db.CollectionName.remove(查询表达式,选项); 查询表达式:匹配要删除的文档,它是一个json对象 选项:{justOne:true/false},是否只删 ...

  3. Mysql 创建权限较小的用户(只对特定数据库有操作权限)

    项目开发过程中,因为root的权限太大,可能对其他数据库造成修改.故创建一权限较小的用户,使其只能对特定的数据库操作,以保证数据安全. 主要语句如下: grant all on bos19.* to ...

  4. mysql的UNIX_TIMESTAMP用法

    UNIX_TIMESTAMP 一般是用于unix的时间戳. 例子: SELECT UNIX_TIMESTAMP("2016-07-11")-- 1468166400SELECT U ...

  5. Creating External Table - KUP-04020

    原因:因为操作系统环境不同,所以换行符也不同,要查看数据文件的换行符 解决方法: 1.如果是苹果系统类的数据文件,则改为:RECORDS DELIMITED BY 0X'0D' 2.如果是window ...

  6. [译]GLUT教程 - 位图字体

    Lighthouse3d.com >> GLUT Tutorial >> Fonts >> Bitmap Fonts 位图字体一般是二维字体.虽然我们会把它放到三维 ...

  7. start with git

    Start with git 1.what is GitHub? GitHub is a code hosting platform for version control and collabora ...

  8. 内核initcall分析

    linux中init相关内容定义在include/linux/init.h initcall相关定义 先看下文件说明,此文件定义的宏主要用于初始化阶段标记函数或初始化数据,之后占用的资源会被释放掉. ...

  9. css3 jQuery实现3d搜索框+为空推断

    <!DOCTYPE html> <html> <head> <title>css3实现3d搜索框</title> <style> ...

  10. sublime使用技巧(1)-- 下载与插件安装

    一.下载 到官网下载最新的版本 https://www.sublimetext.com/ Sublime官方插件网站 https://packagecontrol.io/ 二.插件安装配置 1.打开S ...