赞
踩
学生成绩管理系统Demo,android+servlet(前端+后台)
Hello,这还是自己第一次写博客,有点小激动~
一个完美的系统的展现是源于知识的积累沉淀,感觉自己还是个android知识小白,虽然这个管理系统不是那么完善,但是也花了一些时间,分享给大家,请大家多多指教哈~
我这次使用的是androidstudio和intelliJ IDES,这个系统分为教师和学生登录,我暂时完成了教师端的一些功能。后台servlet连接了数据库
以下展示后台代码目录和android代码目录和mysql
(1)后台代码目录
(2)android代码目录(学生端代码没有实现,不展示了)
(3)数据库五个表
首先来看看我们的登录注册吧
先展示一下下图片哈~
代码如下:
(1)Register1Activity:
package com.example.management;
import android.content.Intent; import android.os.Handler; import android.os.Message; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.RadioGroup; import android.widget.Toast; import com.example.management.Student.StudentHomePageActivity; import com.example.management.Utils.StatusbarUtil; import org.json.JSONException; import org.json.JSONObject; import java.io.IOException; import okhttp3.Call; import okhttp3.FormBody; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; public class Register1Activity extends AppCompatActivity implements View.OnClickListener, RadioGroup.OnCheckedChangeListener{ public static final int Teacher_OPTION = 1; public static final int Student_OPTION = 2; private String str_username = "";//获取用户名 private String str_password = "";//用户密码 private EditText editText_accountr;//注意实例化的位置 private EditText editText_passwordr;// private Button register; private Button jumpToMainr; private RadioGroup radio_group; private String code;//服务器返回的值 int flag = 0; int time; private Handler handler = new Handler(new Handler.Callback() { @Override public boolean handleMessage(Message msg) { //Log.d("123456", "handleMessage: "+msg.obj.toString()); code = jsonToJsonObject(msg.obj.toString()); Log.d("hander", "code: "+code); if (code.equals("0")) {//登录成功,跳转主页面 // MainActivity.isLogin = true; //保存当前信息 Log.d("handler", "登录成功"); // Bundle bundle = new Bundle(); // bundle.putString("id", id); // bundle.putString("account", str_username); // bundle.putString("password", str_password); // bundle.putInt("option", msg.arg1); // bundle.putBoolean("status", true); // UserInfoUtil.saveCurrentInfo(getApplicationContext(), bundle); Toast.makeText(Register1Activity.this, "注册成功", Toast.LENGTH_SHORT).show(); if(flag==Teacher_OPTION){ Intent intent1 = new Intent(Register1Activity.this, TeacherHomePageActivity.class); startActivity(intent1); }else if(flag==Student_OPTION){ Intent intent = new Intent(Register1Activity.this, StudentHomePageActivity.class); startActivity(intent); } //finish(); } else if(code.equals("-1")){//若注册失败,清空输入框,提醒用户重新俗人 Toast.makeText(Register1Activity.this, "账号已存在!", Toast.LENGTH_SHORT).show(); editText_accountr.setText(""); editText_passwordr.setText(""); }else if(code.equals("-2")){ Toast.makeText(Register1Activity.this, "系统繁忙,稍后重试!", Toast.LENGTH_SHORT).show(); editText_accountr.setText(""); editText_passwordr.setText(""); } return true; } }); public String jsonToJsonObject(String json) { Log.d("hello", "jsonToJsonObject: " + json); String code = ""; String message = null; try { JSONObject jsonObject = new JSONObject(json); code = jsonObject.optString("code"); // message = jsonObject.optString("message"); } catch (JSONException e) { e.printStackTrace(); } return code; } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_register1); initView(); } /*** *布局初始化 */ private void initView() { StatusbarUtil.setTransparentWindow(this, false); register = findViewById(R.id.register_btn); editText_accountr = findViewById(R.id.account_register);//须再onCreate里实例化 editText_passwordr = findViewById(R.id.password_register);//须再onCreate里实例化 jumpToMainr = findViewById(R.id.jumpToMainr); radio_group = findViewById(R.id.radio_group); register.setOnClickListener(this); jumpToMainr.setOnClickListener(this); radio_group.setOnCheckedChangeListener(this); } private void sendRequestWithOkHttp() { str_username = editText_accountr.getText().toString();//getText()要放到监听里面//获取用户名 str_password = editText_passwordr.getText().toString();//获取用户密码 new Thread(new Runnable() { @Override public void run() { try { if (flag == Teacher_OPTION) { Log.d("mode", "run: " + flag); requestNet(str_password, "http://10.161.66.7:8080/three/servlet/RegisterTeacherServlet?", Teacher_OPTION); } else if (flag == Student_OPTION) { Log.d("mode", "run: " + flag); requestNet(str_password, "http://10.161.66.7:8080/three/servlet/RegisterStudentServlet?", Student_OPTION); } } catch (Exception e) { e.printStackTrace(); } } }).start(); } /*** *联网注册请求 *@return void *@author zmj *created at 2019/3/20 18:50 */ private void requestNet(String finalStr_password_MD, String s, int option) throws IOException { OkHttpClient client = new OkHttpClient(); RequestBody responseBody = null; if (option == Teacher_OPTION) { responseBody = new FormBody.Builder().add("no", str_username).add("password", finalStr_password_MD).build(); } else if (option == Student_OPTION) { //Log.d("123456", "requestNet: "+123456); responseBody = new FormBody.Builder().add("no", str_username).add("password", finalStr_password_MD).build(); // Log.d("responsd", responseBody.toString()); } Request request = new Request.Builder().url(s).post(responseBody).build(); Call call = client.newCall(request); Response response = call.execute(); Message message = handler.obtainMessage(); message.obj = response.body().string(); message.arg1 = option; handler.sendMessage(message); Log.d("requestNet", (String) message.obj+message.arg1); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.register_btn: sendRequestWithOkHttp(); break; case R.id.jumpToMainr: { Intent intent = new Intent(Register1Activity.this, LoginActivity.class); startActivity(intent); break; } } } @Override public void onCheckedChanged(RadioGroup group, int checkedId) { flag = 0; switch (checkedId) { case R.id.teacherR: flag = 1; break; case R.id.studentR: flag = 2; break; } } }
(2)LoginActivity
package com.example.management;
import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.content.Intent; import android.os.Handler; import android.os.Message; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.RadioGroup; import android.widget.Toast; import com.example.management.Student.StudentHomePageActivity; import com.example.management.Utils.StatusbarUtil; import org.json.JSONException; import org.json.JSONObject; import java.io.IOException; import okhttp3.Call; import okhttp3.FormBody; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; public class LoginActivity extends AppCompatActivity implements View.OnClickListener, RadioGroup.OnCheckedChangeListener{ public static final int Teacher_OPTION = 1; public static final int Student_OPTION = 2; private String id;//获取用户id private String str_username = "";//获取用户名 private String str_password = "";//用户密码 private String code;//服务器返回的值 private EditText accountEditl; private EditText passwordEditl; private Button login; private Button jumpToRegister; private Button back; private RadioGroup radio_group_login; public static int flag; private Handler handler = new Handler(new Handler.Callback() { @Override public boolean handleMessage(Message msg) { //Log.d("123456", "handleMessage: "+msg.obj.toString()); code = jsonToJsonObject(msg.obj.toString()); Log.d("hander", "code: "+code); if (code.equals("0")) { // MainActivity.isLogin = true; //保存当前信息 Log.d("handler", "登录成功"); // Bundle bundle = new Bundle(); // bundle.putString("id", id); // bundle.putString("account", str_username); // bundle.putString("password", str_password); // bundle.putInt("option", msg.arg1); // bundle.putBoolean("status", true); // UserInfoUtil.saveCurrentInfo(getApplicationContext(), bundle); Toast.makeText(LoginActivity.this, "登录成功", Toast.LENGTH_SHORT).show(); if(flag==Teacher_OPTION){ Intent intent1 = new Intent(LoginActivity.this, TeacherHomePageActivity.class); startActivity(intent1); }else if(flag==Student_OPTION){ Intent intent = new Intent(LoginActivity.this, StudentHomePageActivity.class); startActivity(intent); } //finish(); } else if(code.equals("-1")){//若账号不存在,跳转至注册页面 Toast.makeText(LoginActivity.this, "登录失败,请先注册", Toast.LENGTH_SHORT).show(); accountEditl.setText(
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。