private static Connection conn = null; private static final String DRIVER = "org.sqlite.JDBC"; private static final String URL = "jdbc:sqlite:"; private static final String FILENAME = "d:/graduation_examination.db3"; public static Connection getConnection() { try { Class.forName(DRIVER).newInstance(); conn = DriverManager.getConnection(URL + FILENAME); if (conn != null) { System.out.println("-----连接成功-----"); } } catch (Exception e) { e.printStackTrace(); } return conn; } public static void closeConn(Connection connection) { if (connection != null) { try { connection.close(); connection = null; } catch (sqlException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } public static void closePstmt(PreparedStatement pstmt) { try { if (pstmt != null) { pstmt.close(); pstmt = null; } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static void closeRs(ResultSet rs) { try { if (rs != null) { rs.close(); rs = null; } } catch (Exception e) { e.printStackTrace(); } } public static void closeStmt(Statement stmt) { if (stmt != null) { try { stmt.close(); stmt = null; } catch (sqlException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
<body bgcolor="#cac8ff" topmargin="100"> <div align="center"> <form name="login" method="get" action="Teacher/verify.jsp"> <table width="480" border="0" cellspacing="1" cellpadding="1" class="tableBorder"> <tr> <td height="34" colspan="2" align="center" background="/GraduationServer/images/login/login_bg3.gif" class="whitenormal"> 考试管理系统登录 </td> </tr> <tr> <td height="134" colspan="2" background="/GraduationServer/images/login/login_bg1.gif" align="center"> </td> </tr> <tr> <td width="40%" align="right" class="normalText" background="/GraduationServer/images/login/login_bg3.gif"> 用户名: </td> <td width="60%" background="/GraduationServer/images/login/login_bg3.gif"> <input type="text" name="username" class="textBox"> </td> </tr> <tr> <td width="40%" align="right" class="normalText" background="/GraduationServer/images/login/login_bg3.gif"> 密码: </td> <td width="60%" background="/GraduationServer/images/login/login_bg3.gif"> <input type="password" name="password" class="textBox"> </td> </tr> <tr> <td background="/GraduationServer/images/login/login_bg3.gif" align="right"> <input type="submit" name="Submit" value="登录" /> </td> <td background="/GraduationServer/images/login/login_bg3.gif" align="left"> <input type="reset" name="Reset" value="重置" /> </td> </table> </form> </div> <iframe name='hideFrame' style="display: none"></iframe> </body>
<% request.setCharacterEncoding("UTF-8"); String strNextToPage = "main.jsp"; String username = new String(request.getParameter("username") .trim().getBytes("ISO-8859-1"),"UTF-8"); String password = new String(request.getParameter("password") .trim().getBytes("ISO-8859-1"),"UTF-8"); String strMsgInfo = ""; if (username.equals("")) { strMsgInfo = "请输入用户名!"; out.println("<script>parent.alert('" + strMsgInfo + "')</script>"); out .println("<script>history.back(1);</script>"); return; } else if (password.equals("")) { strMsgInfo = "请输入密码!"; out.println("<script>parent.alert('" + strMsgInfo + "')</script>"); out .println("<script>history.back(1);</script>"); return; } TeacherLoginBiz teacherLoginBiz = new TeacherLoginBizImpl(); List<TeacherInfo> teacherInfos = teacherLoginBiz.loginTeacheBiz( username,password); if (teacherInfos.size() == 1) { Iterator<TeacherInfo> iterator = teacherInfos.iterator(); while (iterator.hasNext()) { TeacherInfo teacherInfo = iterator.next(); System.out.println("-----id----" + teacherInfo.getTeacher_id() + ";----name----" + teacherInfo.getTeacher_name() + ";-------pwd------" + teacherInfo.getTeacher_pwd()); session.setAttribute("username",teacherInfo .getTeacher_name()); session.setAttribute("password",teacherInfo .getTeacher_pwd()); } } else { strMsgInfo = "登录失败,用户名或密码错误!"; } if (!strMsgInfo.equals("")) { out.println("<script>parent.alert('" + strMsgInfo + "')</script>"); out .println("<script>parent.location.href='login.jsp';</script>"); return; } out.println("<script>parent.location.href='" + strNextToPage + "';</script>"); %>原文链接:https://www.f2er.com/sqlite/202006.html