Android客户端与服务器交互,登录案例

这篇博客详细介绍了如何实现Android客户端与Web服务器的交互,以登录功能为例。客户端使用Android Studio,依赖FastJSON、OkHttp和Okio库通过HTTP请求与服务器通信。服务器端基于MyEclipse,运用Hibernate框架操作MySQL数据库。博客涵盖了Android布局文件、主界面代码以及服务器端的Hibernate架构、Pojo类、Service接口和实现,还包括数据库操作工具和配置文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

实现了Android客户端与服务器的交互,客户端采用Android Studio开发,Web服务器采用MyEclipse开发,数据库使用MySQL,采用Hibernate框架开发


1、Android客户端采用开发工具为Android Studio,用到的jar包com.alibaba:fastjson:1.2.7

.jar、com.squareup.okhttp:okhttp:2.5.0.jar、com.squareup.okio:okio:1.6.0.jar,客户端采用OkHttp与服务器进行交互,详见

2、Web服务器采用MyEclipse,用到的jar包,主要是Hibernate的jar


一 Android客户端

1.1 布局文件activity_main.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:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:orientation="vertical"
    tools:context=".LoginActivity">

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="@string/loginregister"
        android:textColor="#D10B0B"
        android:textSize="30dp" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >


        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/username" />


        <EditText
            android:id="@+id/etusername"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:inputType="text" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/password" />

        <EditText
            android:id="@+id/etpassword"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:inputType="text" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/login"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/login" />

        <Button
            android:id="@+id/register"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/register" />
    </LinearLayout>

</LinearLayout>

1.2 主界面 LoginActivity.java

在LoginActivity.java中,实现与服务器间的交互主要采用OKHttp架包,这个架包封装了各种与服务器的交互,详见点击打开链接

package com.zsp.applogin.Activi
评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值