web認證源碼
❶ 涓轟粈涔堢幇鍦╳eb娓楅忥紝閮界敤鐨勬槸php鍐欑殑婧愮爜錛
絎涓PHP璇璦鏈韜婕忔礊鐩稿綋澶氾紝灝ゅ叾鏄寰堝氫漢涓嶅枩嬈㈢敤鏈鏂扮増鏈錛岀幇鍦≒HP8閮藉彂甯冧簡錛岀幇鍦ㄧ珶鐒惰繕鏈変竴澶ф壒浜虹敤PHP5.2錛岃秺鏃╃殑鐗堟湰婕忔礊瓚婂氥傛紡媧炲氳嚜鐒跺氨濂藉仛娓楅忋
絎浜孭HPweb妗嗘灦婕忔礊涔熼潪甯稿氥傚浗鍐呮渶甯哥敤鐨凱HP妗嗘灦thinkphp緇忓父鐖嗗嚭鍚勭嶄弗閲嶆紡媧烇紝姣斿5.x鐨勮繙紼嬪彲鎵ц屽懡浠ゆ紡媧烇紝瀵艱嚧澶ч噺浣跨敤姝ゆ嗘灦鐨勭綉絝欎腑鎷涖傝繖涓婕忔礊鍒╃敤涔嬪規槗錛屽仛涓紼嬪簭鍙浠ラ殢渚挎劅鏌撲竴澶ф壒緗戠珯銆傛湁鐨勪漢鍒╃敤榪欎釜婕忔礊鎷垮埌鐨勮倝楦″氬埌鑷宸遍兘鏁頒笉榪囨潵銆
鍙嶈侸avaweb錛屽ぇ澶氭暟浜洪兘浼氱敤sprint鍏ㄥ舵《銆傝孲pringMVC鍜孲pringsecurity鎻愪緵鐨勫畨鍏ㄨよ瘉錛岃搗瀹夊叏鎬ч兘鏄闈炲父寮虹殑銆
鉶界劧Spring涔熷嚭涓浜涙紡媧烇紝浣嗘槸鎴戝嵃璞′腑榪樻病鏈夊嚭榪囬潪甯稿規槗鍒╃敤錛岄潪甯哥畝鍗曞氨鑳芥嬁鍒版渶楂樻潈闄愮殑鍌葷摐寮忔紡媧炪
絎涓夌綉涓婂姡璐╬hp婧愮爜鏈澶氥傚緢澶氫漢鏄鏍規湰涓嶅叿澶囩嫭絝嬬紪紼嬭兘鍔涚殑錛岃繖浜涙墍璋撶殑鈥滅▼搴忓憳鈥濇渶鍠滄㈠共鐨勪簨鏄鍘葷綉涓婁笅杞藉悇縐嶅厤璐規簮鐮侊紝鐒跺悗鏀瑰惂鏀瑰惂灝辯畻鑷宸卞仛浜嗙綉絝欎簡銆
榪欑嶅厤璐規簮鐮侊紝浠PHP灞呭氥備粈涔堢殑dedeCMS錛屼粈涔坸xshop錛寈xmall錛屽井鐩燂紝榪欓噷鍨冨溇PHP婧愮爜綆鐩存槸鍗冪柈鐧懼瓟錛屾紡媧炵櫨鍑恆傚彲浠ヨ存槸榛戝浠鐨勬渶鐖便傜敤榪欑被鍨冨溇婧愮爜鏈鐨勭綉絝欙紝闅忎究涓涓涓瀛︾敓鎹i紦鎹i紦灝辮兘鍏ヤ鏡錛岀畝鐩村拰瑁稿旀病鍟ュ尯鍒銆
鍚屾椂錛屼細鐢ㄨ繖浜涘瀮鍦句唬鐮佸仛緗戠珯鐨勭▼搴忓憳錛屼竴鑸姘村鉤閮戒笉浼氬お楂橈紝鎸夌悊璇磋繛緙栫▼鍏ラ棬閮界畻涓嶄笂銆傝繖浜涙墍璋撶▼搴忚嚜鐒舵牴鏈鏃犳硶鍋氬埌闃叉㈤粦瀹㈠叆渚點
絎鍥涘緢澶氫漢瀹夊叏鎰忚瘑澶宸銆備笉綆′綘鐢ㄤ粈涔堣璦鍋氱綉絝欙紝澶у氶兘瑕佸湪緗戠珯紼嬪簭澶栧湪璺戜竴涓狽ginx錛宎pache錛屾垨鑰匢IS銆傚嵆浣誇嬌鐢↗ava錛孨ginx鍋氬弽鍚戜唬鐞+闈欐佸勭悊錛屽悗闈㈠啀鍔爐omcat鐨勬瀯鏋朵篃寰堝氥
鍑℃槸錛屽緢澶氫漢瑕佷箞鏄鎶鏈涓嶅埌浣嶏紝瑕佷箞鏄鍋鋒噿錛屼笉鍘昏嚜宸辯紪璇憈omcat鎴栬卆pache錛岃屾槸鐢ㄧ綉涓婄幇鎴愮殑鐨勪竴閿瀹夎呭寘鎴栬呭偦鐡滃畨瑁呯▼搴忋傝繖浜涚▼搴忓彲鑳戒細榛樿ゅ畨瑁匬HP鏀鎸併
涔熷氨鏄璇達紝涓浜涘畨鍏ㄦ剰璇嗕笉寮烘垨鑰呮按騫蟲瘮杈冨樊鐨勭▼搴忓憳緙栧啓鐨刯avaweb寰堟湁鍙鑳戒篃浼氭敮鎸丳HP銆
寰堝氫漢鍦ㄥ叆渚墊彁鏉冪殑鏃跺欙紝涓嶇′綘鏄浠涔堢綉絝欙紝閮戒細鍏堣瘯涓涓婸HP鑳戒笉鑳芥墽琛岋紝鍏ヤ鏡鍑犵巼姣旇緝楂樸
鍏充簬鏈鍚庝竴涓闂棰橈紝濡傛灉浣犳壘鍒頒簡javaweb鐨勬紡媧烇紝鍙浠ヤ笂浼犳枃浠朵簡錛屼笅涓姝ヨ佸仛鐨勫氨鏄鎻愭潈銆傝繖涓鏃跺欎綘鐩存帴涓婁紶Java婧愪唬鐮佹槸娌℃湁鐢ㄧ殑銆俻hp鏄鍔ㄦ佹墽琛岀殑錛屾簮鐮佸彲浠ョ洿鎺ヨ鎵ц岋紝鑰孞ava鍒欓渶瑕佺紪璇戙
鎷垮埌涓婁紶鏉冮檺鍚庢兂鎻愭潈錛屽氨蹇呴』鍏堝紕娓呮氬規柟鏈嶅姟鍣ㄧ殑jre鐗堟湰錛岀劧鍚庡啀鏈鍦扮敤鐩稿簲鐨勭増鏈緙栬瘧鍚庯紝鍐嶆妸jar鍖呬紶涓婂幓錛屾墠鑳藉熸墽琛屻
榪欓噷榪樻湁涓涓涓嶅悓錛屼竴鑸琾hp鎻愭潈錛屽彧闇瑕佹嬁鍒扮綉絝欐牴鐩褰曠殑涓婁紶鏉冮檺鍗沖彲銆備絾鏄疛avaweb寰堟湁鍙鑳界綉絝欑殑鏍圭洰褰曪紝鍜屽瓨鏀懼彲鎵ц宩ar鍖呯殑鐩褰曚笉鏄涓涓鐩褰曪紝鎯寵佹墽琛孞ava浠g爜錛屼綘灝卞繀欏繪兂娉曟嬁鍒癹ar鍖呮墍鍦ㄧ洰褰曠殑涓婁紶鏉冮檺錛堝悓鏃朵篃瑕佹嬁鍒扮綉絝欐牴鐩褰曟潈闄愶級錛岃繖鏄涓涓闅劇偣銆
❷ jsp登陸界面源代碼
1、login.jsp文件
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<%@ page import="java.util.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>登錄頁面</title>
</head>
<body>
<form name="loginForm" method="post" action="judgeUser.jsp">
<table>
<tr>
<td>用戶名:<input type="text" name="userName" id="userName"></td>
</tr>
<tr>
<td>密碼:<input type="password" name="password" id="password"></td>
</tr>
<tr>
<td><input type="submit" value="登錄" style="background-color:pink"> <input
type="reset" value="重置" style="background-color:red"></td>
</tr>
</table>
</form>
</body>
</html>
2、judge.jsp文件
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<%@ page import="java.util.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>身份驗證</title>
</head>
<body>
<%
request.setCharacterEncoding("GB18030");
String name = request.getParameter("userName");
String password = request.getParameter("password");
if(name.equals("abc")&& password.equals("123")) {
3、afterLogin.jsp文件
%>
<jsp:forward page="afterLogin.jsp">
<jsp:param name="userName" value="<%=name%>"/>
</jsp:forward>
<%
}
else {
%>
<jsp:forward page="login.jsp"/>
<%
}
%>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>登錄成功</title>
</head>
<body>
<%
request.setCharacterEncoding("GB18030");
String name = request.getParameter("userName");
out.println("歡迎你:" + name);
%>
</body>
</html>
(2)web認證源碼擴展閱讀:
java web登錄界面源代碼:
1、Data_uil.java文件
import java.sql.*;
public class Data_uil
{
public Connection getConnection()
{
try{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
}catch(ClassNotFoundException e)
{
e.printStackTrace();
}
String user="***";
String password="***";
String url="jdbc:sqlserver://127.0.0.1:1433;DatabaseName=***";
Connection con=null;
try{
con=DriverManager.getConnection(url,user,password);
}catch(SQLException e)
{
e.printStackTrace();
}
return con;
}
public String selectPassword(String username)
{
Connection connection=getConnection();
String sql="select *from login where username=?";
PreparedStatement preparedStatement=null;
ResultSet result=null;
String password=null;
try{
preparedStatement=connection.prepareStatement(sql);
preparedStatement.setString(1,username);
result=preparedStatement.executeQuery();//可執行的 查詢
if(result.next())
password=result.getString("password");
}catch(SQLException e){
e.printStackTrace();
}finally
{
close(preparedStatement);
close(result);
close(connection);
}
System.out.println("找到的資料庫密碼為:"+password);
return password;
}
public void close (Connection con)
{
try{
if(con!=null)
{
con.close();
}
}catch(SQLException e)
{
e.printStackTrace();
}
}
public void close (PreparedStatement preparedStatement)
{
try{
if(preparedStatement!=null)
{
preparedStatement.close();
}
}catch(SQLException e)
{
e.printStackTrace();
}
}
public void close(ResultSet resultSet)
{
try{
if(resultSet!=null)
{
resultSet.close();
}
}catch(SQLException e)
{
e.printStackTrace();
}
}
}
2、login_check.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>
<jsp:useBean id="util" class="util.Data_uil" scope="page" />
<%
String username=(String)request.getParameter("username");
String password=(String)request.getParameter("password");
if(username==null||"".equals(username))
{
out.print("<script language='javaScript'> alert('用戶名不能為空');</script>");
response.setHeader("refresh", "0;url=user_login.jsp");
}
else
{
System.out.println("輸入的用戶名:"+username);
String passwordInDataBase=util.selectPassword(username);
System.out.println("密碼:"+passwordInDataBase);
if(passwordInDataBase==null||"".equals(passwordInDataBase))
{
out.print("<script language='javaScript'> alert('用戶名不存在');</script>");
response.setHeader("refresh", "0;url=user_login.jsp");
}
else if(passwordInDataBase.equals(password))
{
out.print("<script language='javaScript'> alert('登錄成功');</script>");
response.setHeader("refresh", "0;url=loginSucces.jsp");
}
else
{
out.print("<script language='javaScript'> alert('密碼錯誤');</script>");
response.setHeader("refresh", "0;url=user_login.jsp");
}
}
%>
</body>
</html>
3、loginSucces.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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<hr size="10" width="26%" align="left" color="green">
<font size="6" color="red" >登錄成功 </font>
<hr size="10" width="26%" align="left" color="green">
</body>
</html>
4、user_login.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=ISO-8859-1">
<title>登錄界面</title>
</head>
<body background="C:Userswin8workspaceLoginimage\_10.jpg" >
<center>
<br><br><br><br><br><br>
<h1 style="color:yellow">Login</h1>
<br>
<form name="loginForm" action="login_check.jsp" method="post">
<table Border="0" >
<tr >
<td>賬號</td>
<td><input type="text" name="username"></td>
</tr>
<tr>
<td>密碼</td>
<td><input type="password" name="password">
</td>
</tr>
</table>
<br>
<input type="submit" value="登錄" style="color:#BC8F8F">
</form>
</center>
</body>
</html>