admin 管理员组

文章数量: 1184232


2024年3月8日发(作者:power是开关的意思吗)

因为要做一个软件注册的功能,所以今天做了一个小例子,这里的服务器是自己的tomcat服务器,做过j2ee的应该是再熟悉不过了。

public class RegisterActivity extends Activity {

private static final String uriConnection

"10.0.2.2:8080/Register/servlet/RegisterServlet";

//private static final String uriConnection

"192.168.0.5:8080/Register/servlet/RegisterServlet";

Button registerButton;

Button registerLaterButton;

ProgressDialog progressDialog;

EditText firstText;

EditText lastText;

EditText emailText;

@Override

protected void onCreate(Bundle savedInstanceState) {

setContentView(er);

te(savedInstanceState);

firstText = (EditText) findViewById(er_first_name_id);

lastText = (EditText) findViewById(er_last_name_id);

emailText = (EditText) findViewById(er_email_id);

registerButton = (Button) findViewById(er_button_id);

registerLaterButton = (Button) findViewById(er_later_button_id);

lickListener(registerListener);

lickListener(registerLaterButtonListener);

}

Handler handler = new Handler() {

public void handleMessage(Message msg) {

s();

finish();

};

};

kListener registerListener = new kListener() {

@Override

public void onClick(View v) {

String firstName = t().toString();

String lastName = t().toString();

String emailName = t().toString();

progressDialog = (,

"Register", "");

=

=

registerToHost(firstName, lastName, emailName);

}

};

// 处理客户端和服务器端的请求

private void registerToHost(String firstName, String lastName,

String emailName) {

HttpPost httpRequest = new HttpPost(uriConnection);

HttpResponse httpResponse = null;

List params = new ArrayList();

if (!("") && !("")

&& !("")) {

(new BasicNameValuePair("firstName", firstName));

(new BasicNameValuePair("lastName", lastName));

(new BasicNameValuePair("emailName", emailName));

}

try {

ity(new UrlEncodedFormEntity(params, _8));

httpResponse = new DefaultHttpClient().execute(httpRequest);

} catch (UnsupportedEncodingException e) {

// TODO Auto-generated catch block

tackTrace();

} catch (ClientProtocolException e) {

// TODO Auto-generated catch block

tackTrace();

} catch (IOException e) {

// TODO Auto-generated catch block

tackTrace();

}

// 处理从服务器短来的数据

if (tusLine().getStatusCode() == 200) {

n("Connection OK");

ptyMessage(0);

/*

* byte[] data = new byte[2048]; try { data =

* Array(ity()); } catch

* (IOException e) { // TODO Auto-generated catch block

* tackTrace(); }

*/

}

}

kListener registerLaterButtonListener = new kListener() {

@Override

public void onClick(View v) {

finish();

}

};

}

layout/:

android:id="@+id/registration_screen_layout_id" android:layout_width="fill_parent"

android:layout_height="fill_parent"

xmlns:android="/apk/res/android">

android:id="@+id/registration_screen_scroll_view_id"

android:background="#ffffffff" android:layout_width="fill_parent"

android:layout_height="fill_parent" android:layout_weight="1.0"

xmlns:android="/apk/res/android">

android:background="#ffffffff" android:layout_width="fill_parent"

android:layout_height="wrap_content"

xmlns:android="/apk/res/android">

android:gravity="left" android:id="@+id/registration_benefits_view_id"

android:paddingLeft="30.0dip" android:paddingTop="10.0dip"

android:paddingRight="30.0dip" android:paddingBottom="10.0dip"

android:layout_width="fill_parent" android:layout_height="wrap_content"

android:text="@string/STR_REGISTRATION_BENEFITS"

android:layout_weight="0.0" />

android:background="@android:drawable/edit_text"

android:paddingLeft="10.0dip" android:paddingRight="10.0dip"

android:layout_width="fill_parent" android:layout_height="wrap_content"

android:layout_marginLeft="30.0dip" android:layout_marginRight="30.0dip"

android:minHeight="60.0dip" android:hint="@string/STR_FIRST_NAME"

android:maxLines="1" android:singleLine="true"

android:selectAllOnFocus="true" android:layout_weight="1.0" />

android:background="@android:drawable/edit_text"

android:paddingLeft="10.0dip" android:paddingRight="10.0dip"

android:layout_width="fill_parent" android:layout_height="wrap_content"

android:layout_marginLeft="30.0dip" android:layout_marginRight="30.0dip"

android:minHeight="60.0dip" android:hint="@string/STR_LAST_NAME"

android:maxLines="1" android:singleLine="true"

android:selectAllOnFocus="true" android:layout_weight="1.0" />

android:background="@android:drawable/edit_text"

android:paddingLeft="10.0dip" android:paddingRight="10.0dip"

android:layout_width="fill_parent" android:layout_height="wrap_content"

android:layout_marginLeft="30.0dip" android:layout_marginRight="30.0dip"

android:minHeight="60.0dip" android:hint="@string/STR_EMAIL"

android:maxLines="1" android:singleLine="true"

android:selectAllOnFocus="true" android:layout_weight="1.0"

android:inputType="textEmailAddress" />

android:layout_height="wrap_content" android:layout_marginTop="5.0dip"

android:layout_weight="0.0"

xmlns:android="/apk/res/android">


本文标签: 服务器 开关 处理 服务器端 客户端