android连接SSM发送和接收数据

原创 2018年04月16日 16:37:47
 //注册账户
            URL url=null;
            HttpURLConnection httpURLConnection=null;
            String result=null,re="";
            BufferedReader bufferedReader=null;
            int y=0,l=0;
            Intent intent1 = new 
                Intent("com.example.space.text2.action.RECEIVER_REGISTER");

            String email = intent.getStringExtra("email");
            String password = intent.getStringExtra("password");
            //连接网络进行注册
            try{
                url = new URL("http://192.168.137.1:8080/SSM5/adduser.json");
            }catch(MalformedURLException e)
            {
                intent1.putExtra("registerstate","网络连接失败");

            }
            try{
                httpURLConnection =(HttpURLConnection)url.openConnection();
                try{
                    httpURLConnection.setRequestMethod("POST");
                }catch(ProtocolException g)
                {
                    l=httpURLConnection.getResponseCode();
                    intent1.putExtra("registerstate","httpURLConnection.setRequestMethod(\"POST\")失败"+String.valueOf(l));
                }

                httpURLConnection.setReadTimeout(5000);
                httpURLConnection.setConnectTimeout(5000);
                httpURLConnection.setDoInput(true);
                httpURLConnection.setDoOutput(true);
                httpURLConnection.setInstanceFollowRedirects(true);


                BufferedWriter  bufferedWriter=null;
                OutputStream outputStream = httpURLConnection.getOutputStream();
                try{
                    bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream,"UTF-8"));
                    //bufferedWriter.write(jsonout.toString());
                    bufferedWriter.write("email="+email+"&"+"password="+password);
                }catch(IOException o){
                    Log.i("mss","bufferedWriter.write IOException");
                }
                bufferedWriter.flush();
                bufferedWriter.close();
                outputStream.close();

                JSONObject jsonObject = null;
                try{
                    result = httpURLConnection.getResponseMessage();
                    bufferedReader = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream()));
                }catch(IOException h)
                {
                    intent1.putExtra("registerstate","httpURLConnection.getResponseMessage();失败");
                }
                String line;
                try{
                    while((line=bufferedReader.readLine())!=null)
                    {
                        re+=line;
                    }
                }catch(IOException e){
                    intent1.putExtra("registerstate","bufferedReader.readLine()失败");
                }
                Log.i("mss",re);

                try{

                    JSONObject jsonObject1 = new JSONObject(re);
                    if(jsonObject1.getInt("status")==1)
                    {
                        //注册成功
                        intent1.putExtra("registerstate","注册成功");
                    }
                    else{
                        intent1.putExtra("registerstate","注册失败");
                    }
                    Log.i("mss","jsonObject1.getInt(\"status\")"+String.valueOf(jsonObject1.getInt("status")));

                }catch(JSONException b)
                {
                    intent1.putExtra("registerstate","new JSONArray(re);失败");
               }

            }
            catch(IOException r)
            {
                intent1.putExtra("registerstate","HttpURLConnection IOException失败");

            }
            catch(NullPointerException r){
                intent1.putExtra("registerstate","HttpURLConnection NullPointerException!\n请连接网络后再注册");
            }



            //返回结果
                //已经注册过
                //注册成功
                //注册失败,请换一个


            //intent1.putExtra("registerstate","注册成功"+result+"      "+re+"<"+String.valueOf(y)+" "+String.valueOf(l));
            sendBroadcast(intent1);
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/superce/article/details/79962611

Android如何用json格式传数据到后台(SSM) 做一个简单的登录流程

哈喽!刚刚开始接触Android, 有很多地方都不同懂,甚至有点想放弃,曾几何时,我会感叹 安卓“从界面到放弃”,但做什么事都要坚持下来,这个登录做了一周了,下面开始进入主题。这篇博客是写Androi...
  • HuChaoQing
  • HuChaoQing
  • 2018-01-18 18:39:45
  • 604

android连接SSM发送和接收数据

//注册账户 URL url=null; HttpURLConnection httpURLConnection=null; ...
  • superce
  • superce
  • 2018-04-16 16:37:47
  • 19

SSM处理接收到的android传来的request请求

@RequestMapping(&quot;/adduser.json&quot;) public void adduserFromClient(HttpServletRequest request...
  • superce
  • superce
  • 2018-04-16 16:38:30
  • 16

手把手教你Android手机与BLE终端通信--连接,发送和接收数据

如果你还没有看上一篇 手把手教你Android手机与BLE终端通信--搜索,你就先看看吧,因为这一篇要接着讲搜索到蓝牙后的连接,和连接后的发送和接收数据。     我的基本思想就是所有蓝牙操作都写在B...
  • dandan_dany
  • dandan_dany
  • 2016-06-27 14:20:39
  • 16826

VCSOCKET操作

  • 2013年06月14日 13:49
  • 6KB
  • 下载

vux前端组件与java ssm框架进行数据交互

这次做的项目,前端框架用到了vux组件,后台用了java的ssm框架,技术都是刚刚接触的,但是颇有感悟,就前台和后台之间的数据交互就搞得我满心忐忑,不过,还是恍然大悟!首先要明白的思路就是,与页面交互...
  • wwyxhqc_zy
  • wwyxhqc_zy
  • 2017-07-13 21:39:01
  • 980

Android+Json+SSM+MySQL后台数据交互模拟云备份云恢复(源码)

Android+Json+SSM+MySQL后台数据交互模拟云备份云恢复(源码)
  • MadCode2222222222222
  • MadCode2222222222222
  • 2017-11-07 13:43:19
  • 643

Android TCP的客户端(请求的发送和响应结果接收)

Android TCP客户端发送请求并接收响应 import android.util.Log; import com.changhong.electric_controll.UDPResp...
  • qq_31490071
  • qq_31490071
  • 2016-06-14 13:15:18
  • 3266

Android蓝牙搜索设备,向其发送数据并接收

From:http://blog.csdn.net/liuyu973971883/article /details/52495054 通过蓝牙传输数据与Socket类似。在...
  • It_BeeCoder
  • It_BeeCoder
  • 2017-01-13 21:36:46
  • 2000

ssm 接收ajax请求数据,并存放到数据库中

前端页面function subbtn() { $.ajax({ url: "/bdis", // 请求的URL type: "POST...
  • AJ1101
  • AJ1101
  • 2017-11-07 23:08:05
  • 335
收藏助手
不良信息举报
您举报文章:android连接SSM发送和接收数据
举报原因:
原因补充:

(最多只允许输入30个字)