From b4da65a6e3b0f777390c4a82a196cb0cec04dc4c Mon Sep 17 00:00:00 2001 From: FJY Date: Wed, 1 Nov 2017 22:45:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=99=BB=E5=BD=95=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=BA=93=E6=80=A7=E8=83=BD=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WebRoot/JSPhandle/login.jsp | 33 +++++--- WebRoot/JSPhandle/login_show.jsp | 130 +++++++++++++++++-------------- 2 files changed, 95 insertions(+), 68 deletions(-) diff --git a/WebRoot/JSPhandle/login.jsp b/WebRoot/JSPhandle/login.jsp index 573d3aa..29d1ce8 100644 --- a/WebRoot/JSPhandle/login.jsp +++ b/WebRoot/JSPhandle/login.jsp @@ -25,11 +25,10 @@ String users = request.getParameter("inputUser"); String pass = request.getParameter("inputPassword"); boolean flag = false; - PreparedStatement sql = null; - ResultSet rs = null; - Connection conn = null; - PreparedStatement vipsql = null; - ResultSet viprs = null; + + + + session.setMaxInactiveInterval(1440); %> @@ -40,6 +39,10 @@ String use = "root"; String password = ""; Class.forName(driver); + try { + PreparedStatement sql = null; + Connection conn = null; + ResultSet rs = null; conn = DriverManager.getConnection(url, use, password); sql = conn.prepareStatement("select * from user where userName=? and password=?"); sql.setString(1, users); @@ -50,9 +53,18 @@ } rs.close(); sql.close(); + conn.close(); + + } catch (Exception ex) { + ex.printStackTrace(); + } + %> <% try { + PreparedStatement vipsql = null; + ResultSet viprs = null; + Connection conn = null; 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=?"); vipsql.setString(1, users); @@ -63,6 +75,9 @@ session.setAttribute("VIPuser", vipinfo); session.setAttribute("Adminuser", adminfo); } + viprs.close(); + vipsql.close(); + conn.close(); } catch (Exception ex) { ex.printStackTrace(); } @@ -80,11 +95,9 @@ <% } - viprs.close(); - vipsql.close(); - rs.close(); - sql.close(); - conn.close(); + + + %> diff --git a/WebRoot/JSPhandle/login_show.jsp b/WebRoot/JSPhandle/login_show.jsp index b59fb2e..cfade58 100644 --- a/WebRoot/JSPhandle/login_show.jsp +++ b/WebRoot/JSPhandle/login_show.jsp @@ -1,47 +1,46 @@ -<%@ page language="java" import="java.util.*" contentType="text/html;charset=utf-8"%> -<% -String path = request.getContextPath(); -String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; -%> +<%@ page language="java" import="java.util.*" + contentType="text/html;charset=utf-8"%> +<% + String path = request.getContextPath(); + String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + + path + "/"; +%> <%@page import="java.sql.Connection"%> <%@page import="java.sql.*"%> <%@page import="java.sql.DriverManager"%> - - - - - - 登录成功 - - - - - - - - - - - <% -java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - -java.util.Date currentTime = new java.util.Date();//得到当前系统时间 - -String str_date1 = formatter.format(currentTime); //将日期时间格式化 -String str_date2 = currentTime.toString(); //将Date型日期时间转换成字符串形式 + --> + + + + + <% + java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + + java.util.Date currentTime = new java.util.Date();//得到当前系统时间 + + String str_date1 = formatter.format(currentTime); //将日期时间格式化 + String str_date2 = currentTime.toString(); //将Date型日期时间转换成字符串形式 String driverClass = "com.mysql.jdbc.Driver"; String url = "jdbc:mysql://localhost:3306/db_school?useUnicode=true&characterEncoding=utf-8"; String user = "root"; String password = ""; - Connection conn = null; - PreparedStatement sql = null; String counter = null; Class.forName(driverClass); - conn = DriverManager.getConnection(url, user, password); - Statement stmt = conn.createStatement(); + Object user0 = session.getAttribute("actualuser"); /* out.println("欢迎"+user0);//输出当前session用户 */ %> @@ -58,30 +57,45 @@ String str_date2 = currentTime.toString(); //将Date型日期时间转换成字 } return ip; }%> - <% - counter = getIpAddr(request); - try { - sql = conn.prepareStatement("update counter set visitCount=visitCount+1"); - int rtn = sql.executeUpdate(); - } catch (Exception ex) { - ex.printStackTrace(); - } - try { - sql = conn.prepareStatement("insert into iplist(IP,times,userName)values(?,?,?)"); - sql.setString(1, counter); - sql.setString(2, str_date1); - sql.setString(3, (String)user0); - int rtn = sql.executeUpdate(); - } catch (Exception ex) { - ex.printStackTrace(); - } - %> - <% + <% + counter = getIpAddr(request); + 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"); + int rtn = sql.executeUpdate(); stmt.close(); - sql.close(); - conn.close(); + sql.close(); + conn.close(); + } catch (Exception ex) { + ex.printStackTrace(); + } + 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.setString(1, counter); + sql.setString(2, str_date1); + sql.setString(3, (String) user0); + int rtn = sql.executeUpdate(); + stmt.close(); + sql.close(); + conn.close(); + } catch (Exception ex) { + ex.printStackTrace(); + } %> - 登录成功.
-<% response.setHeader("refresh","0;url=../mainframe.jsp");%> - - \ No newline at end of file + <% + + %> + 登录成功. +
+ <% + response.setHeader("refresh", "0;url=../mainframe.jsp"); + %> + +