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. react-native 项目实战 -- 新闻客户端(5) -- 完善首页列表数据

    1.Home.js: /** * 首页 */ import React, { Component } from 'react'; import { AppRegistry, StyleSheet, T ...

  2. 早来的圣诞礼物!--android 逆向菜鸟速參手冊完蛋版

    我的说明: 让老皮特整理了这么长时间这个手冊,心里挺过意不去的,回头我去深圳带着他女儿去游乐场玩玩得了,辛苦了.peter! 太多的话语,也描写叙述不出这样的感觉了,得找个时间.不醉不归... 注:下 ...

  3. servlet监听器与事件

    前言 在Servlet 2.4/JSP 2.0中,共同拥有八个Listener接口,六个Event类别. 參考:Servlet中的八大Listener 入门 阅读文件夹 Web监听器 监听器的分类 S ...

  4. boost库常用功能

    1.shared_ptr shared_ptr除了最基本的可以用new初始化以外,还可以使用其他方式初始化.在使用一些c的api时候,这种初始化方式非常有用,如下 boost::shared_ptr& ...

  5. Jenkins Docker 插件

    原文地址:https://wiki.jenkins.io/display/JENKINS/Docker+Plugin Created by magnayn -, last modified by Ni ...

  6. window.location网页URL信息

    window.location属性 描述 hash 设置或获取 href 属性中在井号“#”后面的分段. host 设置或获取 location 或 URL 的 hostname 和 port 号码. ...

  7. 使用rsa进行http传输加密

    目录 1. RSA算法 2. HTTPS 2.1 HTTPS优点 2.2 HTTPS缺点 3. RSA传输加密实现 3.1 所需插件 3.1.1 JS插件 3.1.2 所需JAR 3.1.3 代码 4 ...

  8. mapreduce中reduce中的迭代器只能调用一次。其实迭代器就只能调用一次

    亲测,只能调用一次,如果想想在一次reduce重复使用迭代器中的数据,得先取出来放在list中然后在从list中取出来!!多次读取reduce函数中迭代器的数据 public static void ...

  9. hive中遇到的问题

    ) from t_1 where country ='China' group by (name = 'qq'); 结果图 select * from t_sz_part; 按照理解来说,应该只有一个 ...

  10. Modern.IE,创建现代网站的给力开发工具!

    Modern.IE是微软推出的用来帮助开发者创建现代网站的基本开发工具.作为Web攻城师,最头疼的问题莫过于浏览器兼容性测试,各种类型浏览器,各种版本的浏览器,还有各种头疼的前缀等等.Modern.I ...