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>
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>
2. 黃老師,我做了一個簡單的html 登錄界面,有賬號和密碼輸入以及提交按鈕
(VB) 自動填寫網頁表單參考源碼
VB6中採用WebBrowser自動填寫並提交表單參考源碼,已經可以實現自動填寫並提交。對代碼優化可以達到更好的效果。
Public Sub WebbFormEditing()
Dim i, j As Integer
Dim vForm, vSubmit
Dim vFrame
On Error Resume Next
Set vFrame = WebBrowser1.Document.frames
If IsEmpty(vFrame) Then GoTo ErrorFormEdit
For i = 0 To vFrame.length - 1
On Error Resume Next
vFrame(i).Document.body.innerHTML = tbHtml.Text
Next i
ErrorFormEdit:
On Error GoTo ErrorFormEditEnd
Set vForm = WebBrowser1.Document.Forms
If IsEmpty(vForm) Then GoTo ErrorFormEditEnd
Me.CurWebbState = 3 '填表單
For i = 0 To vForm.length - 1
On Error GoTo ErrorFormEditEnd
If InStr(1, vForm(i).name, "login", vbTextCompare) > 0 Then '登錄
ElseIf InStr(1, vForm(i).name, "search", vbTextCompare) > 0 Or _
InStr(1, vForm(i).name, "find", vbTextCompare) > 0 Then '搜索
Else '其他表單,先填了
On Error Resume Next
vForm(i).onSubmit = ""
For j = 0 To vForm(i).length - 1
If UCase(vForm(i)(j).tagName) = "INPUT" Then 'INPUT
Select Case LCase(vForm(i)(j).Type)
'********************text*********************
Case "text":
'1,鏈接
If InStr(1, vForm(i)(j).name, "url", vbTextCompare) > 0 Or InStr(1, vForm(i)(j).name, "link", vbTextCompare) > 0 Or _
InStr(1, vForm(i)(j).name, "home", vbTextCompare) > 0 Or InStr(1, vForm(i)(j).name, "address", vbTextCompare) > 0 Or _
InStr(1, vForm(i)(j).name, "tags", vbTextCompare) > 0 Then
vForm(i)(j).Value = tbLink.Text
'EMail
ElseIf InStr(1, vForm(i)(j).name, "email", vbTextCompare) > 0 Then
vForm(i)(j).Value = tbEmail.Text
'名稱
ElseIf InStr(1, vForm(i)(j).name, "name", vbTextCompare) > 0 Or InStr(1, vForm(i)(j).name, "user", vbTextCompare) > 0 Or _
InStr(1, vForm(i)(j).name, "author", vbTextCompare) > 0 Then
vForm(i)(j).Value = tbName.Text
'標題
ElseIf InStr(1, vForm(i)(j).name, "title", vbTextCompare) > 0 Or InStr(1, vForm(i)(j).name, "topic", vbTextCompare) > 0 Then
If Len(vForm(i)(j).Value) <= 0 Then vForm(i)(j).Value = tbTitle.Text
'評論,摘要
ElseIf InStr(1, vForm(i)(j).name, "summary", vbTextCompare) > 0 Or InStr(1, vForm(i)(j).name, "comment", vbTextCompare) > 0 Or _
InStr(1, vForm(i)(j).name, "content", vbTextCompare) > 0 Then
vForm(i)(j).Value = tbTextArea.Text
'qq
ElseIf InStr(1, vForm(i)(j).name, "qq", vbTextCompare) > 0 Or InStr(1, vForm(i)(j).name, "icq", vbTextCompare) > 0 Then
vForm(i)(j).Value = tbQQ.Text
'驗證碼
ElseIf InStr(1, vForm(i)(j).name, "Random", vbTextCompare) > 0 Then
Beep
End If
'****************text***************
Case "password"
Case "submit"
Set vSubmit = vForm(i)(j)
End Select
ElseIf UCase(vForm(i)(j).tagName) = "SELECT" Then
ElseIf UCase(vForm(i)(j).tagName) = "TEXTAREA" Then
vForm(i)(j).innerHTML = tbTextArea.Text
End If
Next j
' 當前表單填完,提交
If Not IsEmpty(vSubmit) Then
On Error GoTo ErrorFormEditEnd
Me.LbState.Caption = "提交"
Me.CurWebbState = 4
vSubmit.Click
End If
End If
Next i
If Me.CurWebbState <> 4 Then Me.CurWebbState = 5 '沒有可提交的表單
Exit Sub '結束過程
'出錯退出
ErrorFormEditEnd:
Me.CurWebbState = 11
End Sub
3. 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>
<title>3</title>
</head>
<body>
<div align="center">
<form action="" name="myform">
<table>
<tr>
<td>用戶名:</td>
<td><input type="text" id="user" /></td>
</tr>
<tr>
<td>密 碼:</td>
<td><input type="text" id="password" /></td>
</tr>
<tr>
<td>驗證碼:</td>
<td align="left"><input type="text" size="5" id="code" /></td>
</tr>
</table>
</form>
<table>
<tr>
<td>
<input type="submit" value="提交" onclick=myfun_submit() />
</td>
<td>
<input type="submit" value="重置" onclick=myfun_reset() />
</td>
</tr>
</table>
</div>
<script type="text/javascript">
function myfun_submit(){
var user_val = document.getElementById("user").value;
var password_val = document.getElementById("password").value;
if(user_val==""){
alert("用戶名不能為空!!");
}else if(password_val==""){
alert("密碼不能為空!!!");
}
}
function myfun_reset(){
document.getElementById("user").value = "";
document.getElementById("password").value = "";
document.getElementById("code").value = "";
}
</script>
</body>
</html>
4. 用html代碼編寫一個簡單的登陸界面
<!DOCTYPE html><html lang="zh-CN"><head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>登錄</title>
<link href="css/bootstrap.min.css" rel="stylesheet"></head><body><nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="./">jsp作業</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li><a href="login.html">登錄</a></li>
</ul>
</div>
</div></nav><div class="container">
<div class="row">
<div class="col-md-4">
</div>
<div class="col-md-4">
<form class="form-signin" target="submitFrame" method="post">
<h2 class="form-signin-heading">登錄到jsp作業</h2>
<label for="inputEmail">Email</label>
<input type="email" id="inputEmail" class="form-control" placeholder="請輸入Email" required autofocus><br>
<label for="inputPassword">密碼</label>
<input type="password" id="inputPassword" class="form-control" placeholder="請輸入密碼" required>
<div class="checkbox">
<label>
<input type="checkbox" value="remember-me" checked="checked"> 記住密碼 </label>
</div>
<button type="submit" class="btn btn-primary" id="btn-login">登錄</button>
<a href="reg.html" class="btn btn-default">注冊</a>
</form>
<iframe style="display: none;" name="submitFrame" src="about:blank"></iframe>
</div>
<div class="col-md-4">
</div>
</div>
<script src="js/jquery.min.js"></script></body></html>
5. html登錄界面設置賬號密碼
寫js啊,
<script>
var username = document.getElementsClassName('bt_input')[0];
var password = document.getElementsClassName('bt_input')[1];
var button= document.getElementsClassName('logingBut')[0];
button.onclick=function(){
if(username .value=="user"&&password .value=="123456"){
location.href="下一個網頁的網址";
}else{
alert("賬號或密碼錯誤!");
window.opener = null;
window.open("", "_self");
window.close();
}
}
</script>
把這段代碼放在</body>前面就好了,,純手打,採納哈