[SERVER + mobile phone project] Android + servlet + JSON Comprehensive Case Study: Android combined with Serlvet [3]

Source: Internet
Author: User

It's finally the last minute. I can't wait, so I'm so excited ~~~!

Package COM. example. servletandroiddemo; import COM. example. servletandroiddemo. bean. servletapplication; import COM. example. servletandroiddemo. util. downloadutil; import android. OS. bundle; import android. OS. handler; import android. OS. message; import android. app. activity; import android. view. view; import android. view. view. onclicklistener; import android. widget. button; import android. widget. edittext; import androi D. widget. toast; public class registeractivity extends activity implements onclicklistener {private edittext et_name, et_passwd, et_mail; private button bt_ OK; private handler mhandler; @ overrideprotected void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); mhandler = new handler () {@ overridepublic void handlemessage (Message MSG) {super. handlemessage (MSG); system. out. println (MSG. What); If (MSG. what = servletapplication. fail) {toast. maketext (registeractivity. this, "registration error", 1000 ). show ();} else if (MSG. what = servletapplication. success) {toast. maketext (registeractivity. this, "registered", 1000 ). show ();} else if (MSG. what = servletapplication. error) {toast. maketext (registeractivity. this, "request exception", 1000 ). show () ;}}; setcontentview (R. layout. register); getviews (); setlistener ();} private v Oid getviews () {// todo auto-generated method stubet_name = (edittext) findviewbyid (R. id. name); et_passwd = (edittext) findviewbyid (R. id. passwd); et_mail = (edittext) findviewbyid (R. id. mail); bt_ OK = (button) findviewbyid (R. id. OK);} private void setlistener () {// todo auto-generated method stubbt_ OK .setonclicklistener (this);} @ overridepublic void onclick (view v) {// todo auto-generated method stubswitc H (v. GETID () {case R. id. OK: string name = et_name.gettext (). tostring (). trim (); string passwd = et_passwd.gettext (). tostring (). trim (); string mail = et_mail.gettext (). tostring (). trim (); submitinfo (name, passwd, mail); break ;}} /*** submit registration information ** @ Param name * User name * @ Param passwd * password * @ Param mail * mailbox */private void submitinfo (string name, string passwd, string mail) {// todo auto-generated method stubst Ring registerpath = "http: // 193.168.1.122: 8080/jsondemo/servlet/registerservlet? Type = register & name = "+ name +" & passwd = "+ passwd +" & mail = "+ mail; system. out. println (registerpath); New downloadutil (registerpath, mhandler ). start ();}}

Note:I didn't return the specific data in JSON format here, because I only returned the status code. But it is quite similar. In my complete project, there is such an example, you can see how it is done.

Here is the main idea. If you want to download the complete project, click the following address :(Remember to change the Database Name and access address to your own.)

: Http://download.csdn.net/detail/iliaokun/5749333

Related Article

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.