<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <style> .a{width:500px;height:300px ;border : 1px solid #FF0000 ; left : 240px ; top : 120px ; position : relative ;background-color: purple; text-align: center ;} </style> <body> <hr> <font style="text-shadow: 3px 3px 3px #FF0000"> 不會連接數據庫,所以先默認賬號123,默認密碼000,做練習 </font> <hr> <div class="a"> <h1>銀行自助終端系統</h1> <form action="NewFile1.jsp" method="get"> 卡號<input type="text" name="name"><br> <br><br> 密碼<input type="password" name="password"><br> <br><br> <input type="reset" value="重置" > <input type="submit" value="登陸"> </form> </div> </body> </html>
<%@page import="java.sql.SQLException"%> <%@page import="java.sql.ResultSet"%> <%@page import="java.sql.PreparedStatement"%> <%@page import="java.sql.DriverManager"%> <%@page import="java.sql.Connection"%> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <% String name = request.getParameter("name") ; name = new String(name.getBytes("ISO-8859-1") , "UTF-8" ) ; String password = request.getParameter("password") ; out.write("<br>收到的參數<br>用戶名:"+name+"<br> 密碼:"+password+"<br>") ; if(name.equals("123")) { if(password.equals("000")) { %> <!-- 賬號密碼正確跳轉登陸頁面--> <jsp:forward page="success.jsp"></jsp:forward> <% } else { %> <!-- 賬號正確密碼錯誤跳轉密碼錯誤提示頁面 --> <jsp:forward page="failpassword.jsp"></jsp:forward> <% } } else { %> <!-- 賬號錯誤跳轉賬號錯誤提示頁面 --> <jsp:forward page="failkahao.jsp"></jsp:forward> <% } %> <!-- try { Class.forName("oracle.jdbc.driver.OracleDriver") ; String url ="jdbc:oracle:thin:@localhost:1521:orcl" ; Connection conn = DriverManager.getConnection(url,"test0816","934617699") ; String sql = "select * from account_bank where kahao= ? " ; PreparedStatement ps = conn.prepareStatement(sql) ; ps.setString(1, name); ResultSet rs = ps.executeQuery() ; if(rs.next()) { if(password.equals(rs.getString("passqord"))) { //out.write("登陸成功") ; } else { //out.write("密碼錯誤") ; } } else { out.write(22) ; //out.write("賬號錯誤") ; } } catch (Exception e) { // TODO 自動生成的 catch 塊 e.printStackTrace(); } --> </body> </html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <h2>當輸入賬號錯誤的時候跳轉該到頁面</h2> <br> <h1>卡號不存在!!!!!!</h1> </body> </html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <h2>當輸入密碼錯誤的時候跳轉到該頁面</h2> <br> <h1>密碼錯誤!!!!!!</h1> </body> </html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <h1>當都輸入正確的時候進入該頁面</h1> <br> <h1>登陸成功!</h1> </body> </html>
賬號不對時
卡號正確,密碼錯誤的時候
當密碼卡號都正確時
==================================連接數據庫版======================================
<%@page import="java.sql.SQLException"%> <%@page import="java.sql.ResultSet"%> <%@page import="java.sql.PreparedStatement"%> <%@page import="java.sql.DriverManager"%> <%@page import="java.sql.Connection"%> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <% String name = request.getParameter("name") ; name = new String(name.getBytes("ISO-8859-1") , "UTF-8" ) ; String password = request.getParameter("password") ; out.write("<br>收到的參數<br>用戶名:"+name+"<br> 密碼:"+password+"<br>") ; try { Class.forName("oracle.jdbc.driver.OracleDriver") ; String url ="jdbc:oracle:thin:@localhost:1521:orcl" ; Connection conn = DriverManager.getConnection(url,"test0816","934617699") ; String sql = "select * from account_bank where kahao= ? " ; PreparedStatement ps = conn.prepareStatement(sql) ; ps.setString(1, name); ResultSet rs = ps.executeQuery() ; if(rs.next()) { if(password.equals(rs.getString("password"))) { %> <!-- 賬號密碼正確跳轉登陸頁面--> <jsp:forward page="success.jsp"></jsp:forward> <% } else { %> <!-- 賬號正確密碼錯誤跳轉密碼錯誤提示頁面 --> <jsp:forward page="failpassword.jsp"></jsp:forward> <% } } else { %> <!-- 賬號錯誤跳轉賬號錯誤提示頁面 --> <jsp:forward page="failkahao.jsp"></jsp:forward> <% } } catch (Exception e) { // TODO 自動生成的 catch 塊 e.printStackTrace(); } %> </body> </html>