Web網頁登錄設計


web網頁登陸

 

登陸網頁的簡單功能的實現

輸入用戶名和密碼與數據庫當中的用戶名和密碼匹配上,則登陸成功。

 

首先我們要先配置好web制作所需要的軟件,在mysql數據庫當中建立表,建立用戶名和密碼

 

在java ee上編寫連接mysql數據庫的代碼

 

<%@ page contentType = "text/html; charset=utf-8" import = "java.sql.*" errorPage = "error.jsp" %>
<html>
<head>
</head>
<body>
<div style=text-align:center>
<%

String num = request.getParameter("num");
session.setAttribute("username",num);
String userpassword = request.getParameter("userpassword");
Class.forName("com.mysql.jdbc.Driver");
Connection connect = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/test","root","20153126");
Statement stmt = connect.createStatement();
String sql = "select * from user where name='"+num+"'and userpassword='"+userpassword+"'";
ResultSet i = stmt.executeQuery(sql);
if(i.next())
{
response.setHeader("refresh","1;url = index1.html");
}
else
{
out.println("<script language = 'javaScript'> alert('密碼錯誤,請重新輸入用戶名!');</script>");
response.setHeader("refresh","1;url = login.html");
}
stmt.close();
connect.close();

%>
</div>
</body>
<html>ml>

連接上數據庫之后,在dreamwearver中畫出網頁的登錄界面,轉化成代碼,復制粘貼進去到java ee 中,

代碼:

 

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>無標題文檔</title>
</head>

<body>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<table width="200" border="1">
<tr>
<td width="55">用戶名</td>
<td width="129">&nbsp;</td>
</tr>
<tr>
<td>密碼</td>
<td>&nbsp;</td>
</tr>
</table>
<p>&nbsp; </p>
</body>
</html>
</body>
</html>

在網頁中輸入用戶名和密碼

 

輸入正確的用戶名和密碼后:

代碼:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>無標題文檔</title>
</head>

<body>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>登錄成功!</p>
</body>
</html>

輸入錯誤后:

具體方法:從數據庫中查找登錄界面中輸入的用戶名的密碼,如果有,則返回正確的密碼,否則 ,返回null;然后重寫doget方法,對登錄進行響應,如果輸入的密碼與從數據庫中返回的密碼相同,那么轉到登錄成功后的界面,如果登錄失敗,那么則提示用戶重新登錄。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM