- 浏览: 474216 次
- 性别:
- 来自: 南京
-
文章分类
最新评论
-
fkbld:
楼主给个密码,谢谢了,baild_zr@126.com
ExtJs direct 推送 DEMO -
文思涌动:
你的方法太好用了,感激不尽。
MyEclipse 安装ADT -
zys08:
...
jquery uploadify -
攻城使:
我现在也在学习使用Uploadfiy,摸索中
jquery uploadify -
gksrxn:
liuyulovely 写道怎么解压还要密码,楼主解压的密码是 ...
ExtJs direct 推送 DEMO
android 用户名:________ 密 码:________ submitButton,resetButton (模拟器上访问地址填写 http://10.0.2.2:8080/test/servlet/androidServlet 不用写127.0.0.1或localhost ) 第二部:建立个web项目的一个servlet,接受android请求
package com.isoftstone.cry; import java.io.IOException; import java.util.ArrayList; import java.util.List; import org.apache.http.HttpResponse; import org.apache.http.NameValuePair; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.HttpPost; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.message.BasicNameValuePair; import org.apache.http.protocol.HTTP; import org.apache.http.util.EntityUtils; import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.Entity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; public class LoginActivity extends Activity { private Button submit , reset ; private EditText username , password ; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.login_layout); //实例化组件 username = (EditText)findViewById(R.id.loginName); password = (EditText)findViewById(R.id.loginPsw); submit = (Button)findViewById(R.id.submit); reset = (Button)findViewById(R.id.reset); //添加监听 reset.setOnClickListener(resetListener); submit.setOnClickListener(submitListener); } //resetListener private OnClickListener resetListener = new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub username.setText(""); password.setText(""); } }; //submitListener private OnClickListener submitListener = new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub String _username = username.getText().toString(); String _password = password.getText().toString(); Log.i("android servlet", _username+" "+_password); login(_username,_password); } }; //showDialog private void showDialog(String msg) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage(msg).setCancelable(false) .setPositiveButton("确定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub } }); AlertDialog alert = builder.create(); alert.show(); } //login method private void login(String _username,String _password) { String strUrl = "http://10.0.2.2:8080/test/servlet/androidServlet"; HttpPost request = new HttpPost(strUrl); List<NameValuePair> parameters = new ArrayList<NameValuePair>(); parameters.add(new BasicNameValuePair("name", _username)); parameters.add(new BasicNameValuePair("psw", _password)); try { request.setEntity(new UrlEncodedFormEntity(parameters,HTTP.UTF_8)); HttpResponse response = new DefaultHttpClient().execute(request); if(response.getStatusLine().getStatusCode()==200){ String msg = EntityUtils.toString(response.getEntity()); showDialog(msg); } } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TableLayout android:id="@+id/tableLayout1" android:layout_width="match_parent" android:layout_height="wrap_content" > <TableRow android:id="@+id/tableRow1" android:layout_width="wrap_content" android:layout_height="wrap_content" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/username" /> <EditText android:id="@+id/loginName" android:layout_width="wrap_content" android:layout_height="wrap_content" android:inputType="textPersonName" > <requestFocus /> </EditText> </TableRow> <TableRow android:id="@+id/tableRow2" android:layout_width="wrap_content" android:layout_height="wrap_content" > <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/password" /> <EditText android:id="@+id/loginPsw" android:layout_width="wrap_content" android:layout_height="wrap_content" android:inputType="textPassword" /> </TableRow> <TableRow android:id="@+id/tableRow3" android:layout_width="wrap_content" android:layout_height="wrap_content" > <Button android:id="@+id/submit" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="submit" /> <Button android:id="@+id/reset" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="reset" /> </TableRow> </TableLayout> </LinearLayout>
添加访问权限
<uses-permission android:name="android.permission.INTERNET"/> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <activity android:name=".LoginActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>
test项目 package com.isoftstone.cry; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class androidServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { System.out.println("****************/servlet/androidServlet*************"); String name = request.getParameter("name"); String psw = request.getParameter("psw"); response.setContentType("text/html"); response.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); out.print("login success"); out.flush(); out.close(); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); } }
发表评论
-
为什么 iOS 应用比 Android 应用更美观
2012-05-14 20:26 1110为什么 iOS 应用比 Android 应用更美观?《连线》杂 ... -
android 入门 ScrollView
2012-05-07 09:45 1163点击按钮,从scrollview跳转到horizontalsc ... -
android 入门 ListView - ArrayAdapter、SimpleAdapter、SimpleCursorAdapter
2012-05-04 15:27 1406package com.zte.android.lesst ... -
android入门 SeekBar
2012-04-26 20:40 1295package com.zte.android.lessi ... -
android 入门 Gallery
2012-04-25 20:03 1022package com.zte.android.lesst ... -
android入门 spinner
2012-04-23 22:27 1005package com.zte.android.lessi ... -
MyEclipse 安装ADT
2012-04-22 14:23 23197未整理 .... 自己留下点记忆,以后用的时候看看回顾.... ... -
android入门 alertDialog、progressDialog datepickerdialog、timepickerdialog
2012-04-19 09:12 1835package com.zte.android.lession ... -
android 入门 datepicker timepicker
2012-04-16 21:42 1106package com.zte.android.lessi ... -
android 入门 CheckBox
2012-04-16 21:11 1117package com.zte.android.lession ... -
android 入门 imageView
2012-04-16 21:10 1056package com.zte.android.lession ... -
android 入门 radioGroup
2012-04-15 17:15 1154package com.zte.android.lession ... -
android 入门 imageButton
2012-04-15 16:28 1192package com.zte.android.lession ... -
android 入门 textview editText 跑马灯 和 高亮显示 SpannableString
2012-04-07 19:40 5345package com.zte.android.lession ... -
android 入门 AlarmManager 例子
2012-03-28 22:35 2316package com.isoftstone.cry; ... -
android 入门 NotificationManager结合BroadcastReceiver 例子
2012-03-28 21:16 1601package com.isoftstone.cry; ... -
android入门 上一步 下一步 保存数据 DEMO
2012-03-24 20:38 4290DEMO 木有注视 吼吼 ~~~ package com ... -
android 入门 ImageSwitcher
2012-03-23 21:36 907package com.isoftstone.cry; ... -
android 入门demo Tab选项卡
2012-03-24 20:39 1379package com.isoftstone.cry; ... -
android 入门demo 进度条
2012-03-24 20:39 1411package com.isoftstone.cry; ...
相关推荐
- **HTTP通信**:在这个demo中,Android客户端与PC服务端是通过HTTP协议进行通信的。HTTP(超文本传输协议)是互联网上应用最广泛的一种网络协议,用于从万维网服务器传输超文本到本地浏览器的传输协议。 - **...
9. **移动应用兼容**:现代摄像头系统往往也支持移动端访问,通过iOS或Android应用进行控制,这意味着开发者还需要熟悉相应的移动开发平台和框架。 10. **监控平台集成**:在企业级应用中,海康摄像头通常会与专业...
1. **网络权限**:Android系统对网络访问有严格的限制,开发者需要在AndroidManifest.xml中声明INTERNET权限,否则应用无法建立网络连接。 2. **FTP服务器库**:通常,Android开发者会使用第三方库如Apache Commons...
在Android应用开发中,网络咨询服务通常涉及到HTTP和HTTPS协议,它们是互联网上应用最广泛的数据交换协议。HTTP(超文本传输协议)用于传输超媒体信息,如HTML文档;HTTPS(安全套接层超文本传输协议)则是在HTTP的...
3. **端口映射**:由于安卓的安全机制,可能需要开启USB调试,通过ADB(Android Debug Bridge)将本地端口映射到手机端口,以便外部设备可以通过特定端口访问手机上的服务。 4. **测试与连接**:一旦服务器软件配置...