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