模拟操作银行登入页面。

<%@ 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>

<style>
.a
{
	390px;
	height:290px;
	background-color:#CCC;
	margin-left:400px;	
	margin-top:10px;
	
	}
.b{ width :390px;
	height:55px;
	background-color:#03C;
	margin-left:0px;	
	margin-top:0px;
	position:relative;
	line-height:55px;text-align:center
	}
.c{ line-height:40px;text-align:center
	
	}
</style>
</head>
<body>

<div class="a">
	<div class="b"><font color="#FFFFFF" >银行登入系统</font>
    	<form action="A.jsp"method="post">
       	用户名:
       	 <input type="text" name="name" placeholder="请输入用名户名"style=" 200px; height:40px"/><br>
		密码:&nbsp&nbsp&nbsp&nbsp
		<input <input type="password"name="password" placeholder="请输入密码" style=" 200px; height:40px"/><br><br>
		<input type="submit" value="提交" style=" 100px; height:40px"/>
        </form>
	</div>

</div>

</body>
</html>

  

<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@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>
<%

//访问数据库
try
{
	Class.forName("oracle.jdbc.driver.OracleDriver");

	Connection conn=DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:orcl", 
		"test0816", "123456");
	String sql="select * from ATM where name=? and password=?";
	PreparedStatement ps= conn.prepareStatement(sql);
	ps.setString(1, "name");
	ps.setString(1, "password");
	ResultSet rs = ps.executeQuery();
	if(rs.next())
	{
			out.write("登入成功");
	}
	else
	{
		out.write("登入失败");
	}

}
catch(Exception e)
{
	e.printStackTrace();

}
%>
<br>
<% 
String name =request.getParameter("name"); 
//字符集转码
name=new String (name.getBytes("ISO-8859-1"),"UTF-8");
String password =request.getParameter("password"); 

out.write("用户名:"+name+"<br>");
out.write("密码:"+password);

if(name.equals("张三"))
{
    if(password.equals("123456"))
    {
%>
        <!-- 账号密码正确跳转登陆页面-->
        <jsp:forward page="success.jsp"></jsp:forward>
<% 
    }
    else
    {
%>
        <!-- 账号正确密码错误跳转密码错误提示页面 -->
        <jsp:forward page="failPassword.jsp"></jsp:forward>
<% 
    }
}
else
{
%>
    <!-- 账号错误跳转账号错误提示页面 -->
    <jsp:forward page="failName.jsp"></jsp:forward>
<% 
}

%>
</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>
跳转登入成功的页面......<br>
登入成功!
</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>
用户名输入错误或不存在的页面<br>
用户名不存在!
</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>
密码输入错误跳转页面。。。。<br>
密码错误!
</body>
</html>

 

<%@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 cairnumber =request.getParameter("cairnumber");
String password =request.getParameter("password");
if(cairnumber==null || password == null)
{
out.write("请正确登录系统");

}
else
{
	Class.forName("oracle.jdbc.driver.OracleDriver");
	Connection conn =DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl",
			"test0816","123456");
	
	PreparedStatement ps =conn.prepareStatement("select*from ATM where cairnumber=? and password=?");
	ps.setString(1, cairnumber);
	ps.setString(2, password);
	ResultSet rs =ps.executeQuery();
	if(rs.next())
	{
		
		out.write("用户名和密码正确,登入成功");
	}
	else
	{
		out.write("用户名或密码错误");
	}
	rs.close();
	ps.close();
	conn.close();
//数据验证

//连接数据库

	
}



%>


</body>
</html>

  在web中连接数据库,odjbc6.jar的包要放在WEB-INF目录下的lib文件夹下面

 

原文地址:https://www.cnblogs.com/liuyanzeng/p/6009407.html