login.jsp
<%@ 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">"Content-type"Content="text/html; Charset=utf-8"><title>insert title Here</title>"check.jsp"Method="Post"><!--action to write the JSP page to be forwarded--Card number:<input type="text"Name="Cardid"><br>Password:<input type="Password"Name="Password"><br><input type="Submit"Value="Login"><br></form></body>Check.jsp Ojdbc6.jar, put it in Lib.
<% @page import="Java.sql.ResultSet"%><% @page import="Java.sql.DriverManager"%><% @page import="java.sql.Connection"%><% @page import="java.sql.PreparedStatement"%><%@ 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">"Content-type"Content="text/html; Charset=utf-8"><title>insert title here</title>This page is to receive the user input card number and password, to verify, verify that the database request object is responsible for receiving--><%//Receive DataString Cardid=request.getparameter ("Cardid"); String Password=request.getparameter ("Password"); //the first two received the data, the acceptance is finished, the verification data//Be sure the data is received.//data validation Check user name password if(cardid==NULL|| password==NULL|| Cardid.equals ("")|| Password.equals (""))//You have to make sure there are data??? { out. Write ("please log into the system correctly"); } Else { out. Write (Cardid); out. Write (password); } //connecting to a databaseClass.forName ("Oracle.jdbc.driver.OracleDriver"); Connection Conn=Drivermanager.getconnection ("Jdbc:oracle:thin: @localhost: 1521:orcl", "test0816","123456"); PreparedStatement PS=Conn.preparestatement ("SELECT * from T_bankcard where cardid=?"+"And password=? and state= ' 1 '"); Ps.setstring (1, Cardid); Ps.setstring (2, password); ResultSet RS=Ps.executequery (); if(Rs.next ()) { out. Write ("user name and password are correct"); } Else { out. Write ("incorrect user name or password"); } //Freeing ResourcesRs.close (); Ps.close (); Conn.close ();%></body>login.jsp
<%@ 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">"Content-type"Content="text/html; Charset=utf-8"><title>insert title Here</title>"check2.jsp"Method="Post"><!--action to write the JSP page to be forwarded--Card number:<input type="text"Name="Cardid"><br>Password:<input type="Password"Name="Password"><br><input type="Submit"Value="Login"><br></form></body>Carddao.java built under the Java Resources src package
Package Com.hanqi.web;import java.sql.connection;import java.sql.preparedstatement;import java.sql.ResultSet; Import Java.sql.sqlexception;import Com.mchange.v2.c3p0.ComboPooledDataSource; Public classCarddao {PrivateCombopooleddatasource cpds=NewCombopooleddatasource ("helloc3p0"); //To build a connection pool object from a configuration file Publicboolean checklogin (String cardid,string password) {Boolean RTN=false; Try{Connection conn=cpds.getconnection (); PreparedStatement PS=Conn.preparestatement ("SELECT * from T_bankcard where cardid=?"+"And password=? and state= ' 1 '"); Ps.setstring (1, Cardid); Ps.setstring (2, password); ResultSet RS=Ps.executequery (); RTN=rs.next ();// } Catch(SQLException e) {//TODO Auto-generated catch blockE.printstacktrace (); } returnRtn; } }
check2.jsp webcontent
<% @page import="Com.hanqi.web.CardDAO"%><%@ 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">"Content-type"Content="text/html; Charset=utf-8"><title>insert title here</title>String Cardid=request.getparameter ("Cardid"); String Password=request.getparameter ("Password");if(cardid==NULL|| password==NULL|| Cardid.equals ("")|| Password.equals ("")){ out. Write ("Please login correctly");}Else{//Check login InformationCarddao cd=NewCarddao ();if(Cd.checklogin (Cardid,password)) { out. Write ("Landing Success");}Else{ out. Write ("Login Failed");} }%></body>Make a bank card user login page, submit the database for login verification, and jump to different pages according to the verification results.