java用户登录源代码 java登录实现原理

用java程序编写一个简单的登录界面怎么写?程序如下:
mport java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
@SuppressWarnings("serial")
public class MainFrame extends JFrame {
JLabel lbl1 = new JLabel("用户名:");
JLabel lbl2 = new JLabel("密码:");
JTextField txt = new JTextField("admin",20);
JPasswordField pwd = new JPasswordField(20);
JButton btn = new JButton("登录");
JPanel pnl = new JPanel();
private int error = 0;
public MainFrame(String title) throws HeadlessException {
super(title);
init();
}
private void init() {
this.setResizable(false);
pwd.setEchoChar('*');
pnl.add(lbl1);
pnl.add(txt);
btn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if ("admin".equal花憨羔窖薏忌割媳公颅s(new String(pwd.getPassword()))){
pnl.removeAll();
JLabel lbl3 = new JLabel();
ImageIcon icon = new ImageIcon(this.getClass().getResource("pic.jpg"));
lbl3.setIcon(icon);
pnl.add(lbl3);
}
else{
if(error3){
JOptionPane.showMessageDialog(null,"密码输入错误,请再试一次");
error;
}
else{
JOptionPane.showMessageDialog(null,"对不起 , 您不是合法用户");
txt.setEnabled(false);
pwd.setEnabled(false);
btn.setEnabled(false);
}
}
}
});
}
public static void main(String[] args) {
MainFrame frm = new MainFrame("测试");
frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frm.setBounds(100, 100, 300, 120);
frm.setVisible(true);
}
}
编程的注意事项:
1、Java是一门面向对象编程语言,不仅吸收了C语言的各种优点 , 还摒弃了C里难以理解的多继承、指针等概念,因此Java语言具有功能强大和简单易用两个特征 。Java语言作为静态面向对象编程语言的代表,极好地实现了面向对象理论,允许程序员以优雅的思维方式进行复杂的编程 。
2、 Java具有简单性、面向对象、分布式、健壮性、安全性、平台独立与可移植性、多线程、动态性等特点 。Java可以编写桌面应用程序、Web应用程序、分布式系统和嵌入式系统应用程序等 。
3、2006年11月13日,Java技术的发明者Sun公司宣布,将Java技术作为免费软件对外发布 。Sun公司正式发布的有关Java平台标准版的第一批源代码,以及Java迷你版的可执行源代码 。从2007年3月起 , 全世界所有的开发人员均可对Java源代码进行修改 。
java编写一个登陆和注册信息的源代码,最简单的就可以,不需要数据库的那种你这个不用数据库真的是有点难搞
我写了个用集合存储的 , 你看看 , 能否帮上你
java.util.ListString list = new ArrayListString();
list.add("qq=123");//存储的时候用(用户名=密码)的形式
list.add("ww=456");
String username = "qq";
String password = "123";
for (int i = 0; ilist.size(); i) {
String num = username"=" password;
if(num.equals(list.get(i))){
System.out.println("登录成功");
break;
}
}
用JAVA编写一个用户或注册登录界面 。请哪位高手能够写下具体的代码,谢谢效果图
代码
!DOCTYPE html
html
head
meta charset="UTF-8"
title先锋图书馆管理系统-登录/title
style
*{
margin: 0;
padding: 0;
list-style: none;
}
#top{
width: 1000px;
height: 95px;
margin: 0 auto;
margin-top: 25px;
}
#top_top{
width: 1000px;
height: 65px;
background: deepskyblue;
}
#top_top_left{
width: 300px;
height: 65px;
float: left;
}
#top_top_leftlabel{
width: 200px;
height: 65px;
color: white;
float: right;
}
#top_top_left#a2{
padding-left: 10px;
padding-top: 20px;
font-size: 16px;
}
#top_bottom{
width: 1000px;
height: 30px;
}
#top_bottom_left{
width: 340px;
height: 30px;
line-height: 30px;
font-size: 12px;
background: skyblue;
color: white;
text-indent: 2em;
float: left;
}
#top_bottom_right{
width: 660px;
height: 30px;
line-height: 30px;
font-size: 12px;
color: blueviolet;
text-align: center;
float: right;
background: lightskyblue;
}
#content{
width: 1000px;
height: 600px;
margin: 0 auto;
background:#587FBA;
}
#content#text{
width: 1000px;
height: 50px;
line-height: 50px;
padding-top: 100px;
font-size: 36px;
font-family:"楷体";
font-weight: bold;
text-align: center;
}
#content#login{
width: 480px;
height: 210px;
margin-top: 20px;
margin-left: 260px;
background: #85A0CB;
}
#content#loginimg{
float: left;
}
#content#login#select{
width: 305px;
height: 210px;
float: right;
}
#content#login#selectdiv{
width: 230;
height: 30px;
margin-left: 30px;
}
#content#login#select#d1{
margin-top:30px;
margin-bottom: 3px;
}
#content#login#selectp{
font-size: 14px;
margin-left: 95px;
}
#bottom{
width: 1000px;
height: 35px;
line-height: 35px;
margin: 0 auto;
background: deepskyblue;
text-align: center;
color: white;
}
/style
/head
body
div id="top"
div id="top_top"
div id="top_top_left"
img src="https://www.04ip.com/post/img/test/a13.png" width="78px" height="65px"label id="a2"先锋图书馆系统管理平台/label
/div
/div
div id="top_bottom"
div id="top_bottom_left"当前位置 : 首页系统管理登录/div
div id="top_bottom_right"当前时间 : label id="lable"/label/div
/div
/div
div id="content"
div id="text"欢迎登录先锋图书馆管理系统/div
div id="login"
img src="https://www.04ip.com/post/img/test/a14.png"width="175px" height="210px"/
form id="select"
div id="d1"用户名: nbsp;nbsp;input type="text" //div
div密nbsp; 码: nbsp;nbsp;input type="password" //div
p
input type="radio" name="user" value="https://www.04ip.com/post/read"/读者nbsp;nbsp;nbsp;nbsp;
input type="radio" name="user" value="https://www.04ip.com/post/admin"/管理员
/pbr/
p
input type="button" value="https://www.04ip.com/post/确定" style="width: 50px;" onclick="put()"/nbsp;nbsp;nbsp;nbsp;
input type="reset" value="https://www.04ip.com/post/重置" style="width: 50px;"/
/p
/form
/div
/div
div id="bottom"欣欣科技有限公司版权所有/div
/body
script type="text/javascript" src="https://www.04ip.com/post/JQuery/jquery.js"/script
script type="text/javascript" src="https://www.04ip.com/post/js/GetCurrentTime.js"/script
script
//验证用户名和密码
function put(){
var d = $("#selectdivinput");//获取用户名和密码
var name = d[0].value;
var pass = d[1].value;
var user = null;
var r = document.getElementsByName("user");//获取用户类型
for(i=0;ir.length;i){
if(r[i].checked){
user=r[i].value;
}
}
//console.log(name","pass","user);//输出测试
if(user==null){
window.alert("请选择用户类型!");
}else if(user=="admin"name!="admin"){
window.alter("用户名错误!");
}else if(user=="admin"name=="admin"pass!="123456"){
window.alert("密码错误!");
}else if(name=="admin"pass=="123456"user=="admin"){
window.location.href="https://www.04ip.com/post/work_02_welcome.html";//在js中在本页面中打开新链接
}else{
window.alert("用户名错误");
}
}
/script
/html
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
tdinput type="submit" value="https://www.04ip.com/post/登录" style="background-color:pink" input
type="reset" value="https://www.04ip.com/post/重置" 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="https://www.04ip.com/post/%=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
{
publicConnection 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;
}
publicString 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();//可执行java用户登录源代码的查询
if(result.next())
password=result.getString("password");
}catch(SQLException e){
e.printStackTrace();
}finally
{
close(preparedStatement);
close(result);
close(connection);
}
System.out.println("找到java用户登录源代码的数据库密码为:" password);
return password;
}
publicvoid close (Connection con)
{
try{
if(con!=null)
{
con.close();
}
}catch(SQLException e)
{
e.printStackTrace();
}
}
publicvoid close (PreparedStatement preparedStatement)
{
try{
if(preparedStatement!=null)
{
preparedStatement.close();
}
}catch(SQLException e)
{
e.printStackTrace();
}
}
publicvoid 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" ""
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" ""
html
head
meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"
titleInsert 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" ""
html
head
meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"
title登录界面/title
/head
bodybackground="C:\Users\win8\workspace\Login\image\9dcbdc339e72a5663b5c289fb5573c13_10.jpg"
center
brbrbrbrbrbr
h1 style="color:yellow"Login/h1
br
form name="loginForm" action="login_check.jsp" method="post"
table Border="0"
tr
td账号/td
tdinput type="text" name="username"/td
/tr
tr
td密码/td
tdinput type="password" name="password"
/td
/tr
/table
br
input type="submit" value="https://www.04ip.com/post/登录" style="color:#BC8F8F"
/form
/center
/body
/html
【java用户登录源代码 java登录实现原理】java用户登录源代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java登录实现原理、java用户登录源代码的信息别忘了在本站进行查找喔 。

    推荐阅读