jsp登入頁面的簡單一實例 雛形_JSP編程

來源:互聯網
上載者:User

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>

歡迎介面:

尚未註冊,直接登入的時候:

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

進入註冊介面:

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

註冊成功,跳轉登入介面:

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

登入時,密碼出錯:5秒後重新登入

                                 

帳號密碼輸入正確,進入首頁面:

<%@ 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登入頁面的簡單一實例 雛形全部內容了,希望大家多多支援雲棲社區~

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.