我想找个以一个javabean作为连接数据库的模板,用数据库里面保存的用户信息来验证用户的登录的例子,网页文件时jsp的,主要要解决的问题是提取了数据出来之后怎么和上一个页面传过来的“用户名”和“密码”进行对比验证,在线等谢谢!!!!!
想找一个jsp用户登录模块的例子
- 提问者网友:無理詩人
- 2021-04-27 07:13
- 五星知识达人网友:蓝房子
- 2021-04-27 07:55
如果你是直接从jsp 跳转到jsp 的话
<%
request.setCharacterEncoding("gbk");
String uname=request.getParameter("userName"); //获得登录页面的登录名
String upass=request.getParameter("userPass"); //获得登录页面的登录密码
UserInfoDao uDao=new UserInfoDao();
boolean result= uDao.checkLogin(uname,upass); //根据登录名和密码验证是否存在
if(result==true){
%>
欢迎你<%= uname%>
<%}else{%>
登录失败!
<%}
%>
public class UserInfoDao extends DataBase{
private Connection con;
private PreparedStatement titlesQuery;
private ResultSet res;
//根据登录名和密码验证是否存在
public boolean checkLogin(String uname,String upass){
boolean result=false;
try{
con=this.getConnection();
titlesQuery=con.prepareStatement(" select upass from userInfo where uname = ? ");
titlesQuery.setString(1, uname);
res=titlesQuery.executeQuery();
while(res.next()){
if (res.getString("upass").equals(upass)) {
result=true;
}
}
}catch(SQLException exception){
exception.printStackTrace();
}finally{
this.closeAll(con, titlesQuery, res);
}
return result;
}
}