解释一段jsp代码 越详细越好 最好每句都有 谢谢

来源:百度知道 编辑:UC知道 时间:2024/09/27 17:30:21
Condb con=new Condb();
Show show=new Show();
String name=request.getParameter("name");
String password=request.getParameter("password");
String sql="select * from tb_Person where Username='"+name+"' and Password='"+password+"'";
ResultSet rs=con.executeQuery(sql);
if(rs.next()){
String strsql=rs.getString(1);
session.setAttribute("name",name);
session.setAttribute("password",password);
session.setAttribute("groupid",strsql);
response.sendRedirect("index.htm");
}else{
out.print(show.errorBox("你输入的用户名或密码有误","错误信息"));
out.close();
}
con.close();
%>

//实例化一个连接,看你后面的意思应该是获得一个数据库连接
Condb con=new Condb();
//也是实例化一个对象,看后面的意思,应该是输出错误原因
Show show=new Show();
//获得请求中"name"的值
String name=request.getParameter("name");
//获得请求中"password"的值
String password=request.getParameter("password");
//查询语句 将请求中的用户名和密码与数据库中的数据进行对应
String sql="select * from tb_Person where Username='"+name+"' and Password='"+password+"'";
//获得查询的结果集
ResultSet rs=con.executeQuery(sql);
//遍历查询结果
if(rs.next()){
//获得表中第一个字段的值
String strsql=rs.getString(1);
//在session保存name的值 在其他地方我们可以使用session.getAttribute("name");来获得这个值。
session.setAttribute("name",name);
//在session保存password的值
session.setAttribute("password",password);
//在session保存strsql的值 在这里保存的是差性能条件
session.setAttribute("groupid",strsql);
//跳转页面至index.htm
response