系统注册登录查看信息忘记密码项目+maven后端app前端+mob平台短信验证+阿里云服务器部署
作者:互联网
系统注册登录查看信息忘记密码项目+maven后端app前端+mob平台短信验证+阿里云服务器部署
IDEA编写后端代码
maven项目的创建
数据库连接
建表,数据库增删查改操作
对每个函数功能模块测试
后端网页编写及测试
用json实现与客户端的数据传输
maven项目的创建
数据库操作
部分代码:
package Servlet;
import lab2.*;
import net.sf.json.JSONObject;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.security.MessageDigest;
@WebServlet("/Sign")
public class Sign extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public Sign() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.setContentType("text/html;charset=UTF-8");
String username = request.getParameter("username").trim();
String password = request.getParameter("password").trim();
PrintWriter out = response.getWriter();
UserOp uo = new UserOp();
PersonOp po = new PersonOp();
DB_conn_op sjk = null;
try {
sjk = new DB_conn_op();
} catch (Exception e) {
e.printStackTrace();
}
JSONObject res = new JSONObject();
boolean flag = false;//username是否存在
try {
flag = uo.findUser1(new User(username,password),sjk);
if(flag){//如果找到user
Person p = po.findPerson1(username,sjk);
res.put("username",p.getUsername());
res.put("name",p.getName());
if(p.getAge()!=null)
res.put("age",p.getAge().toString());
else res.put("age","");
if(p.getTeleno()!=null)
res.put("teleno",p.getTeleno());
else res.put("teleno","");
}
else res.put("error","登陆失败,用户名或密码错误");
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(res);
out.println(res);
try {
sjk.close();
} catch (Exception e) {
e.printStackTrace();
}
out.close();
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
android编写客户端代码
mob平台申请短信验证服务
layout布局的设计和编写
实现activity函数,前端后端进行数据传输
使用哪个手机进行测试
部分代码:
package com.example.client;
import androidx.appcompat.app.AppCompatActivity;
import android.os.AsyncTask;
import android.widget.Button;
import android.os.Bundle;
import android.view.*;
import android.content.*;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import org.json.JSONObject;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class MainActivity extends AppCompatActivity {
private EditText username;
private EditText password;
private TextView err;
private Button b1;//注册按钮
private Button b2;//登录按钮
private Button b3;//忘记密码按钮
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
username = (EditText) findViewById(R.id.username);
password = (EditText) findViewById(R.id.password);
err = (TextView) findViewById(R.id.message);
b1 = (Button) findViewById(R.id.register);
b2 = (Button) findViewById(R.id.login);
b3 = (Button) findViewById(R.id.login_error);
}
public void sign(View view) { //登录按键的响应按键
String user = username.getText().toString();
String pass = password.getText().toString();
if (user.isEmpty() || pass.isEmpty()) {
err.setText("登录失败,用户名或密码不能为空");
err.setVisibility(View.VISIBLE);
} else {
err.setText(null);
err.setVisibility(View.INVISIBLE);
new SignInProcess().execute(user,pass);
}
}
public void signUp(View view) { //注册按键的响应按键
Intent intent = new Intent(MainActivity.this, RegisterActivity.class);
startActivity(intent);
}
public void forget(View view) { //注册按键的响应按键
Intent intent = new Intent(MainActivity.this, ChangepassActivity.class);
startActivity(intent);
}
private class SignInProcess extends AsyncTask<String, String, String> {
@Override
protected String doInBackground(String... params) {
String username = params[0];
String password = params[1];
String result = "";
String s_url = "http://101.132.124.216:8080/myservice/Sign?username="+username+"&password="+password;
System.out.println(s_url);
try {
URL url = new URL(s_url);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setUseCaches(false);
conn.connect();
InputStream is = conn.getInputStream();
InputStreamReader reader = new InputStreamReader(is, "UTF-8");//获取服务器数据实现从字节流到字符流转换
int temp;
while((temp=reader.read()) != -1) {
result += (char)temp;
}
} catch(Exception e) {
err.setText("登录失败,网络错误");
err.setVisibility(View.VISIBLE);
e.printStackTrace();
}
System.out.println(result);
return result;
}
@Override
protected void onPostExecute(String result) {
try {
JSONObject result_json = new JSONObject(result);
if(result_json.has("error")) {
String error_code;
error_code = result_json.getString("error");
err.setText(error_code);
err.setVisibility(View.VISIBLE);
password.setText(null);
} else {
SignInSuccess(result_json);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
private void SignInSuccess(JSONObject info) {
Intent intent=new Intent();
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setClass(this,WelcomeActivity.class);
Toast.makeText(this,"登录成功",Toast.LENGTH_SHORT).show();
try {
intent.putExtra("username", info.getString("username"));
intent.putExtra("name", info.getString("name"));
intent.putExtra("age", info.getString("age"));
intent.putExtra("teleno", info.getString("teleno"));
} catch (Exception e) {
e.printStackTrace();
}
startActivity(intent);
}
}
项目部署
购买阿里云学生机
配置云服务器环境
标签:username,String,import,app,maven,intent,new,mob,password 来源: https://blog.csdn.net/m0_45020051/article/details/111932988