修复登录数据库性能错误
This commit is contained in:
@@ -25,11 +25,10 @@
|
|||||||
String users = request.getParameter("inputUser");
|
String users = request.getParameter("inputUser");
|
||||||
String pass = request.getParameter("inputPassword");
|
String pass = request.getParameter("inputPassword");
|
||||||
boolean flag = false;
|
boolean flag = false;
|
||||||
PreparedStatement sql = null;
|
|
||||||
ResultSet rs = null;
|
|
||||||
Connection conn = null;
|
|
||||||
PreparedStatement vipsql = null;
|
|
||||||
ResultSet viprs = null;
|
|
||||||
|
|
||||||
session.setMaxInactiveInterval(1440);
|
session.setMaxInactiveInterval(1440);
|
||||||
%>
|
%>
|
||||||
@@ -40,6 +39,10 @@
|
|||||||
String use = "root";
|
String use = "root";
|
||||||
String password = "";
|
String password = "";
|
||||||
Class.forName(driver);
|
Class.forName(driver);
|
||||||
|
try {
|
||||||
|
PreparedStatement sql = null;
|
||||||
|
Connection conn = null;
|
||||||
|
ResultSet rs = null;
|
||||||
conn = DriverManager.getConnection(url, use, password);
|
conn = DriverManager.getConnection(url, use, password);
|
||||||
sql = conn.prepareStatement("select * from user where userName=? and password=?");
|
sql = conn.prepareStatement("select * from user where userName=? and password=?");
|
||||||
sql.setString(1, users);
|
sql.setString(1, users);
|
||||||
@@ -50,9 +53,18 @@
|
|||||||
}
|
}
|
||||||
rs.close();
|
rs.close();
|
||||||
sql.close();
|
sql.close();
|
||||||
|
conn.close();
|
||||||
|
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
%>
|
%>
|
||||||
<%
|
<%
|
||||||
try {
|
try {
|
||||||
|
PreparedStatement vipsql = null;
|
||||||
|
ResultSet viprs = null;
|
||||||
|
Connection conn = null;
|
||||||
vipsql = conn.prepareStatement(
|
vipsql = conn.prepareStatement(
|
||||||
"select userName,case when VIP = 1 then 'VIP用户' else '普通用户' end as VIP,case when Administrator = 1 then '管理员' else '' end as Administrator from show_user where userName=?");
|
"select userName,case when VIP = 1 then 'VIP用户' else '普通用户' end as VIP,case when Administrator = 1 then '管理员' else '' end as Administrator from show_user where userName=?");
|
||||||
vipsql.setString(1, users);
|
vipsql.setString(1, users);
|
||||||
@@ -63,6 +75,9 @@
|
|||||||
session.setAttribute("VIPuser", vipinfo);
|
session.setAttribute("VIPuser", vipinfo);
|
||||||
session.setAttribute("Adminuser", adminfo);
|
session.setAttribute("Adminuser", adminfo);
|
||||||
}
|
}
|
||||||
|
viprs.close();
|
||||||
|
vipsql.close();
|
||||||
|
conn.close();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -80,11 +95,9 @@
|
|||||||
<jsp:forward page="login_fail.jsp" />
|
<jsp:forward page="login_fail.jsp" />
|
||||||
<%
|
<%
|
||||||
}
|
}
|
||||||
viprs.close();
|
|
||||||
vipsql.close();
|
|
||||||
rs.close();
|
|
||||||
sql.close();
|
|
||||||
conn.close();
|
|
||||||
%>
|
%>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
<%@ page language="java" import="java.util.*" contentType="text/html;charset=utf-8"%>
|
<%@ page language="java" import="java.util.*"
|
||||||
|
contentType="text/html;charset=utf-8"%>
|
||||||
<%
|
<%
|
||||||
String path = request.getContextPath();
|
String path = request.getContextPath();
|
||||||
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
|
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
|
||||||
|
+ path + "/";
|
||||||
%>
|
%>
|
||||||
<%@page import="java.sql.Connection"%>
|
<%@page import="java.sql.Connection"%>
|
||||||
<%@page import="java.sql.*"%>
|
<%@page import="java.sql.*"%>
|
||||||
@@ -9,39 +11,36 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.
|
|||||||
|
|
||||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<base href="<%=basePath%>">
|
<base href="<%=basePath%>">
|
||||||
<title>登录成功</title>
|
<title>登录成功</title>
|
||||||
<meta http-equiv="pragma" content="no-cache">
|
<meta http-equiv="pragma" content="no-cache">
|
||||||
<meta http-equiv="cache-control" content="no-cache">
|
<meta http-equiv="cache-control" content="no-cache">
|
||||||
<meta http-equiv="expires" content="0">
|
<meta http-equiv="expires" content="0">
|
||||||
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
|
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
|
||||||
<meta http-equiv="description" content="This is my page">
|
<meta http-equiv="description" content="This is my page">
|
||||||
<!--
|
<!--
|
||||||
<link rel="stylesheet" type="text/css" href="styles.css">
|
<link rel="stylesheet" type="text/css" href="styles.css">
|
||||||
-->
|
-->
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<%
|
<%
|
||||||
java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
|
|
||||||
java.util.Date currentTime = new java.util.Date();//得到当前系统时间
|
java.util.Date currentTime = new java.util.Date();//得到当前系统时间
|
||||||
|
|
||||||
String str_date1 = formatter.format(currentTime); //将日期时间格式化
|
String str_date1 = formatter.format(currentTime); //将日期时间格式化
|
||||||
String str_date2 = currentTime.toString(); //将Date型日期时间转换成字符串形式
|
String str_date2 = currentTime.toString(); //将Date型日期时间转换成字符串形式
|
||||||
String driverClass = "com.mysql.jdbc.Driver";
|
String driverClass = "com.mysql.jdbc.Driver";
|
||||||
String url = "jdbc:mysql://localhost:3306/db_school?useUnicode=true&characterEncoding=utf-8";
|
String url = "jdbc:mysql://localhost:3306/db_school?useUnicode=true&characterEncoding=utf-8";
|
||||||
String user = "root";
|
String user = "root";
|
||||||
String password = "";
|
String password = "";
|
||||||
|
|
||||||
Connection conn = null;
|
|
||||||
PreparedStatement sql = null;
|
|
||||||
String counter = null;
|
String counter = null;
|
||||||
Class.forName(driverClass);
|
Class.forName(driverClass);
|
||||||
conn = DriverManager.getConnection(url, user, password);
|
|
||||||
Statement stmt = conn.createStatement();
|
|
||||||
Object user0 = session.getAttribute("actualuser");
|
Object user0 = session.getAttribute("actualuser");
|
||||||
/* out.println("欢迎"+user0);//输出当前session用户 */
|
/* out.println("欢迎"+user0);//输出当前session用户 */
|
||||||
%>
|
%>
|
||||||
@@ -61,27 +60,42 @@ String str_date2 = currentTime.toString(); //将Date型日期时间转换成字
|
|||||||
<%
|
<%
|
||||||
counter = getIpAddr(request);
|
counter = getIpAddr(request);
|
||||||
try {
|
try {
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement sql = null;
|
||||||
|
conn = DriverManager.getConnection(url, user, password);
|
||||||
|
Statement stmt = conn.createStatement();
|
||||||
sql = conn.prepareStatement("update counter set visitCount=visitCount+1");
|
sql = conn.prepareStatement("update counter set visitCount=visitCount+1");
|
||||||
int rtn = sql.executeUpdate();
|
int rtn = sql.executeUpdate();
|
||||||
|
stmt.close();
|
||||||
|
sql.close();
|
||||||
|
conn.close();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement sql = null;
|
||||||
|
conn = DriverManager.getConnection(url, user, password);
|
||||||
|
Statement stmt = conn.createStatement();
|
||||||
sql = conn.prepareStatement("insert into iplist(IP,times,userName)values(?,?,?)");
|
sql = conn.prepareStatement("insert into iplist(IP,times,userName)values(?,?,?)");
|
||||||
sql.setString(1, counter);
|
sql.setString(1, counter);
|
||||||
sql.setString(2, str_date1);
|
sql.setString(2, str_date1);
|
||||||
sql.setString(3, (String)user0);
|
sql.setString(3, (String) user0);
|
||||||
int rtn = sql.executeUpdate();
|
int rtn = sql.executeUpdate();
|
||||||
|
stmt.close();
|
||||||
|
sql.close();
|
||||||
|
conn.close();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
%>
|
%>
|
||||||
<%
|
<%
|
||||||
stmt.close();
|
|
||||||
sql.close();
|
|
||||||
conn.close();
|
|
||||||
%>
|
%>
|
||||||
登录成功. <br>
|
登录成功.
|
||||||
<% response.setHeader("refresh","0;url=../mainframe.jsp");%>
|
<br>
|
||||||
</body>
|
<%
|
||||||
|
response.setHeader("refresh", "0;url=../mainframe.jsp");
|
||||||
|
%>
|
||||||
|
</body>
|
||||||
</html>
|
</html>
|
||||||
Reference in New Issue
Block a user