Android Network programming-landing Combat Project (i)

Source: Internet
Author: User

By writing the client, server-side code to complete an Android landing combat project


The project is divided into 6 parts

    1. Server: Servlet

    2. Client: Activity (interface)

    3. Client: Thread and handler

    4. Client: Httpclient-httpget

    5. Client: Httpclient-httppost

The client is our mobile client.


The first part. Server: Servlet

Server-side development tools MYECLIPSEFORSPRING+TOMCAT8, mainly using Jsp+servlet build project.

First step: Create a new Java_web project

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/5D/E7/wKiom1UmZJSTY8X-AAEu1mq29pM406.jpg "title=" Qq20150409193728.png "alt=" Wkiom1umzjsty8x-aaeu1mq29pm406.jpg "/>

Part II: Create a new Loginservlet package, create a new servlet under it

package loginservlet;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  AndroidLoginServler extends HttpServlet {private static final long  Serialversionuid = 1l;public androidloginservler ()  {super ();} Public void doget (Httpservletrequest request, httpservletresponse response) throws  servletexception, ioexception {this.dopost (Request, response); System.out.println ("Doget");}  Url  address// http://localhost:8080/android_client/servlet/androidloginservler? Loginname=yu&loginpassword=123public void dopost (httpservletrequest request,  Httpservletresponse response) Throws servletexception, ioexception {system.out.println ("DoPost"); Request.setcharacterencoding ("UTF-8"); String loginname = request.getparameter ("LoginName"); String loginpassword = request.getparameter ("Loginpassword"); System.out.println (LoginName); System.out.println (Loginpassword);//  Unified character   Avoid garbled response.setcharacterencoding ("UTF-8"); Response.setcontenttype ("Text/html;charset=utf-8"); printwriter out = null;try {/* *  Login Business Judgment  */out=response.getwriter ();if  (Loginname.equals ("Yu")  && loginpassword.equals ("123"))  {//  Login Success Out.print ("Success ");}  else {//  Login Failed Out.print ("failed");}}  finally {if  (Out != null) Out.close ();}}

Fourth Step: Verify the success, run the project

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/5D/E2/wKioL1UmZszD5NS6AACtoSn_ddM631.jpg "style=" float: none; "title=" Qq20150409194050.png "alt=" Wkiol1umzszd5ns6aactosn_ddm631.jpg "/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/5D/E2/wKioL1UmZs3B5jFhAAD20VGtAys702.jpg "style=" float: none; "title=" Qq20150409194103.png "alt=" Wkiol1umzs3b5jfhaad20vgtays702.jpg "/>

If the console outputs the following, it represents a successful

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/5D/E7/wKiom1UmZcCha8pcAAViAeiC2eo833.jpg "title=" Qq20150409194120.png "alt=" Wkiom1umzccha8pcaaviaeic2eo833.jpg "/>



Android Network programming-landing Combat Project (i)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.