欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

jsp登录页面的简单实例 雏形

程序员文章站 2023-11-13 15:50:28
jsp登录页面的简单实例 雏形 <%@ page language="java" contenttype="text/html; charset=utf-8...

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">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>欢迎页面</title>
</head>
<body>
<%
session.invalidate();//销毁session

%>

<a href="denglu.jsp" >亲,请登录</a>
<a href="zhuce.jsp">注册</a>
</body>
</html>

欢迎界面:

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">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>登录</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登录</font></td></tr>
  <tr height="30">
    <td width="80" align="right">用户名:</td>             
    <td><input type="text" name="username"></td></tr>
  <tr height="30">
    <td width="80" align="right"> 密  码:</td>
    <td> <input type="password" name="password"></td></tr>
    <tr><td height="40" align="center" colspan="2">
    <input type="submit" value="登录">
    </td></tr>
 </table>
</form>
</body>
</html>

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">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>注册</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注册</font></td></tr>
  <tr height="30">
    <td width="80" align="right">用户名:</td>             
    <td><input type="text" name="username"></td></tr>
  <tr height="30">
    <td width="80" align="right"> 密  码:</td>
    <td> <input type="password" name="password"></td></tr>
    <tr><td height="40" align="center" colspan="2">
    <input type="submit" value="提交">
    </td></tr>
 </table>
</form>
</body>
</html>

jsp登录页面的简单实例 雏形

注册成功,跳转登录界面:

<%@ 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>检测跳转中</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{
  
   //连接数据库
   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("数据库连接成功");
   statement st = conn.createstatement();
   resultset rs = st.executequery(str);
   if(rs.next()){
     if(name.equals(rs.getstring(2))){
       out.println("对不起,用户名已使用。");
       out.println("<br>建议使用用户名:" + name +"99"); 
       response.setheader("refresh", "5;url=zhuce.jsp");
     }
   }else{
     int a = st.executeupdate(str1);
     if(a == 1){
       out.println("恭喜你,注册成功");
       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>

jsp登录页面的简单实例 雏形

登录时,密码出错:5秒后重新登录

jsp登录页面的简单实例 雏形                                 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">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>主页面</title>
</head>
<body>
主页面
<%
object obj = session.getattribute("username");
if(obj != null){
  string str = obj.tostring();
  out.println(str + "登陆成功");
}else{
  out.println("登录超时,请重新登录"); 
  response.setheader("refresh", "5;url=denglu.jsp");
}
%>
<br>

<a href="yemian.jsp">退出账号</a>

</body>
</html>

jsp登录页面的简单实例 雏形

以上就是小编为大家带来的jsp登录页面的简单实例 雏形全部内容了,希望大家多多支持~