Simple example of jsp login page
<% @ 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> Welcome page </ title>
</ head>
<body>
<%
session.invalidate (); // Destroy the session
%>
<a href="denglu.jsp"> Dear, please log in </a>
<a href="zhuce.jsp"> Sign up </a>
</ body>
</ html>
Welcome Screen:
When not yet registered, when logging in directly:
<% @ 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> Sign in </ title>
</ head>
<body>
<form action = "test_denglu.jsp" method = "post">
<table width = "300" height = "300" border = "0" align = "center">
<tr height = "80" align = "center">
<td colspan = "2"> <font size = "24"> OO login </ font> </ td> </ tr>
<tr height = "30">
<td width = "80" align = "right"> Username: </ td>
<td> <input type = "text" name = "username"> </ td> </ tr>
<tr height = "30">
<td width = "80" align = "right"> Password: </ td>
<td> <input type = "password" name = "password"> </ td> </ tr>
<tr> <td height = "40" align = "center" colspan = "2">
<input type = "submit" value = "login">
</ td> </ tr>
</ table>
</ form>
</ body>
</ html>
Enter the registration interface:
<% @ 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> Sign up </ title>
</ head>
<body>
<form action = "test_zhuce.jsp" method = "post">
<table width = "300" height = "300" border = "0" align = "center">
<tr height = "80" align = "center">
<td colspan = "2"> <font size = "24"> OO registration </ font> </ td> </ tr>
<tr height = "30">
<td width = "80" align = "right"> Username: </ td>
<td> <input type = "text" name = "username"> </ td> </ tr>
<tr height = "30">
<td width = "80" align = "right"> Password: </ td>
<td> <input type = "password" name = "password"> </ td> </ tr>
<tr> <td height = "40" align = "center" colspan = "2">
<input type = "submit" value = "submit">
</ td> </ tr>
</ table>
</ form>
</ body>
</ html>
Registration is successful, jump to login interface:
<% @ page language = "java" contentType = "text / html; charset = UTF-8"
pageEncoding = "UTF-8" import = "java.sql. *"%>
<! 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> Detect Jumping </ title>
</ head>
<body>
<%
String name = new String (request.getParameter ("username"). GetBytes ("ISO-8859-1"), "UTF-8");
String pw = request.getParameter ("password");
String str = "select * from USERS WHERE username = '" + name + "'";
String str1 = "insert into users values (xuhao.nextval, '" + name + "', '" + pw + "')";
try {
//Connect to the database
Connection conn = null;
Class.forName ("oracle.jdbc.driver.OracleDriver");
String strURL = "jdbc: oracle: thin: @localhost: 1521: SP";
conn = DriverManager.getConnection (strURL, "test", "123");
System.out.println ("Database connection succeeded");
Statement st = conn.createStatement ();
ResultSet rs = st.executeQuery (str);
if (rs.next ()) {
if (name.equals (rs.getString (2))) {
out.println ("Sorry, the username is already used.");
out.println ("<br> Recommended username:" + name + "99");
response.setHeader ("refresh", "5; URL = zhuce.jsp");
}
} else {
int a = st.executeUpdate (str1);
if (a == 1) {
out.println ("Congratulations, the registration was successful");
session.setAttribute ("username", name);
response.setHeader ("refresh", "3; URL = denglu.jsp");
}
}
rs.close ();
st.close ();
conn.close ();
} catch (Exception e) {
e.printStackTrace ();
}
%>
<br> <br>
</ body>
</ html>
Password error during login: login again in 5 seconds
Enter the account password correctly, enter the main page:
<% @ 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> Main page </ title>
</ head>
<body>
home page
<%
Object obj = session.getAttribute ("username");
if (obj! = null) {
String str = obj.toString ();
out.println (str + "Successfully logged in");
} else {
out.println ("Login timed out, please log in again");
response.setHeader ("refresh", "5; URL = denglu.jsp");
}
%>
<br>
<a href="yemian.jsp"> Sign out of account </a>
</ body>
</ html>
The above is a simple example of the jsp login page brought to you by everyone. I hope all of you support the Yunqi community ~