用户登录的代码编写思路

首先,用户在jsp界面输入账号密码,传值到servlet里或spring mvc的controller里,通过

String num = request.getParameter("num");
String password = request.getParameter("password");

接受后,通过调用,studentServiceImpl.validateUser(num, password);再传到数据操作类中去。

public int login(String tel,String password) {
int result;
String sql ="select * from reader where rtel=? and rpassword=?";
try {
init();
ps=conn.prepareStatement(sql);
ps.setString(1, tel);
ps.setString(2, password);
rs= ps.executeQuery();
while(rs.next()) {
return result = 1;
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
if (ps != null) {
try {
ps.close();
close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
return -1;
}

if(result>0){
List<String> list = dBhelper.SeleteUserByTel(tel);
session.setAttribute("rno",list.get(0));
session.setAttribute("name",list.get(1));
response.getWriter().print("true");
}else{
response.getWriter().print("false");
}

此时判断int的大小,再通过数据操作类的另一个方法,查询到该主键(学号)的其他信息,dBhelper.SeleteUserByTel(tel);

之后可以存到session里去。

猜你喜欢

转载自www.cnblogs.com/ChangeMyWorld/p/10851236.html