📄 checklogin.jsp
字号:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
if(!session.isNew()) //消除以前登陆得影响
session.removeAttribute("user");
%>
<html>
<jsp:useBean id="user" scope="session" class="jspD.User"/>
<jsp:setProperty name="user" property="name"/>
<jsp:setProperty name="user" property="pwd"/>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>检验用户</title>
</head>
<body>
<%
if(request.getParameter("pwd").equals("")){
out.print("<h2>密码不能为空!!</h2>");
}else{
String name=user.getName(); //get the content form Bean but not: request.getParameter("name");
String pwd=user.getPwd(); //get the content form Bean but not: request.getParameter("pwd");
String type;
String url="jdbc:microsoft:sqlserver://localhost:1499;DatabaseName=jspDB";
String DBuser="sa";
String password="sa";
// try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
Connection conn= DriverManager.getConnection(url,DBuser,password);
Statement stmt=conn.createStatement();
String queryStr="select * from users where name='"+name+"'";
ResultSet rs=stmt.executeQuery(queryStr);
// }catch(Exception e){
// e.printStrackTrace();
// }
if(!rs.next())
{
out.print("<h3 align=center><font color=Red>用户不存在!!</font></h3>");
out.print("<hr width='50%'>");
out.print("<h5 align=center><a href='login.jsp' target='_self'>返回</a></h5>");
}
else{
do{ //此处不能用while(){},因为上面(!re.next())已经把游标移动到第一个记录了。
//rs.getString() return the string with the length which has defined in database!!Must be cut before use.
if(request.getParameter("pwd").equals("")){
out.print("<h4 align=center><font color=Red>密码错误!请重新输入 <font><h4>");
out.print("<a href='./login.jsp' target='_self'>返回</a>");
}
if(pwd.equals(rs.getString(2).trim())){
user.setEmail(rs.getString(4).trim()); //设置用户邮箱
user.setTgh(rs.getString(5).trim());
user.setID(rs.getInt(6));
if(rs.getInt(3)==1){//rs.getString(3).trim().equals("1")){ //we must use equals() but not "=="
user.setType(1); //设置用户类型
type=new String("消费者");
out.print("<h4 align=center>欢迎"+type+":"+name+"</h4>");
out.print("<hr width='50%'>");
out.print("<h5 align=center><a href='./consumer/consumer.jsp' target='_self'>继续</a></h5>");
}
else if(rs.getInt(3)==2){
user.setType(2);
type=new String("产品供应商");
out.print("<h4 align=center>欢迎"+type+":"+name+"</h4>");
out.print("<hr width='50%'>");
out.print("<h5 align=center><a href='./business/business.jsp' target='_self'>继续</a></h5>");
}
else if(rs.getInt(3)==3){
user.setType(3);
type=new String("管理员");
out.print("<h4 align=center>欢迎"+type+":"+name+"</h4>");
out.print("<hr width='50%'>");
out.print("<h5 align=center><a href='./manager/manager.jsp' target='_self'>继续</a></h5>");
}
}else{
out.print("<h4 align=center><font color=Red>密码错误!请重新输入 <font><h4>");
out.print("<hr width='50%'>");
out.print("<a href='./login.jsp' target='_self'>返回</a>");
}
}while(rs.next());
}
}//end of if(pwd==null)
/*some test functions
out.print("<p> name:"+user.getName());
out.print("<p> pwd:"+user.getPwd());
out.print("<p>DBname:"+rs.getString(1));
out.print("<p>DBpwd:"+rs.getString(2)+pwd);out.print("<p>");
out.print(pwd.length());
out.print("<p>");
out.print(rs.getString(2).trim().length());*/
%>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -