📄 login.jsp
字号:
<%@ include file="include.inc"%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<%
//获得请求的参数。
String id=request.getParameter("userId");
String psw=request.getParameter("password");
//连接数据库
Class.forName(CLASSFORNAME);
Connection con = DriverManager.getConnection(SERVANDDB,USER,PWD);
Statement statement=con.createStatement();
String isCorrect="select * from user_info where userId='" + id + "' and password='" + psw + "'";
ResultSet result=statement.executeQuery(isCorrect);
session.setAttribute("isLog",new String("0"));
if(!result.next())
{
response.sendRedirect("index.jsp");//账号或密码错误,转入错误页面
result.close();
statement.close();
con.close();
}
//如果查询后有记录,说明登录验证成功。
else
{
//保存登录信息到session对象中。
session.setAttribute("name",result.getString("name"));
session.setAttribute("id",result.getString("userId"));
session.setAttribute("email",result.getString("email"));
session.setAttribute("fav",result.getString("fanvcategory"));
session.setAttribute("userType",new Integer(result.getInt("userType")));
System.out.println(session.getAttribute("userType"));
session.setAttribute("isLog",new String("1"));
int count=result.getInt("userLogCount");
session.setAttribute("userLogCount",new Integer(count));
count++;
session.setAttribute("userLastLogTime",result.getString("userLastLogTime"));
java.util.Date time1=new java.util.Date();//获得系统当前时间
String sqltime=new Timestamp(time1.getTime()).toString();//将当前时间转换成sql server可以识别的对象
//更新登录信息。
statement.execute("update user_info set userLogCount="+count+",userLastLogTime='"+sqltime+"' where userId='" + id +"'");
//关闭数据库连接相关的资源。
statement.close();
con.close();
//把页面派发到目的
response.sendRedirect("index.jsp");
}
%>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -