Make a bank card user login page, submit the database for login verification, and jump to different pages according to the verification results.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.