登陆窗口代码(窗体登录界面代码)
admin 发布:2022-12-19 03:43 107
本篇文章给大家谈谈登陆窗口代码,以及窗体登录界面代码对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
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="登录" 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" ""
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
body background="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="登录" style="color:#BC8F8F"
/form
/center
/body
/html
JAVA 制作登陆窗口
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Login extends JFrame{
nbsp;public Login() {
nbsp;nbsp;setLayout(new GridLayout(1,2));//网格布局,1行2列,放置左面板和右面板
nbsp;nbsp;setTitle("发表iPhone说说");//设置窗口标题
nbsp;nbsp;setSize(550,300);//设置大小
nbsp;nbsp;setLocationRelativeTo(null);//设置窗口位置
nbsp;nbsp;setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//设置窗口关闭按钮动作
nbsp;nbsp;//左面板
nbsp;nbsp;JPanel leftPanel = new JPanel();
nbsp;nbsp;leftPanel.setBorder(BorderFactory.createTitledBorder("登录手机腾讯网"));//给左面板加上边框,并添加文字
nbsp;nbsp;leftPanel.setLayout(new BorderLayout());
nbsp;nbsp;JPanel leftPanelTop = new JPanel();
nbsp;nbsp;JPanel leftPanelBottom = new JPanel();
nbsp;nbsp;leftPanel.add(leftPanelTop, BorderLayout.CENTER);
nbsp;nbsp;leftPanel.add(leftPanelBottom, BorderLayout.SOUTH);
nbsp;nbsp;leftPanelTop.setLayout(new GridLayout(3,2));//网格布局,3行2列
nbsp;nbsp;nbsp;nbsp;nbsp;
nbsp;nbsp;//========================请在下面写上你的代码
nbsp;nbsp;JLabel qq = new JLabel("QQ号码");
nbsp;nbsp;JTextField qqNum = new JTextField();
nbsp;nbsp;JLabel pwd = new JLabel("QQ密码");
nbsp;nbsp;JPasswordFieldnbsp; qqPwd = new JPasswordField();
nbsp;nbsp;JLabel verify = new JLabel("验证码");
nbsp;nbsp;JTextField qqVer = new JTextField();
nbsp;nbsp;leftPanelTop.add(qq);
nbsp;nbsp;leftPanelTop.add(qqNum);
nbsp;nbsp;leftPanelTop.add(pwd);
nbsp;nbsp;leftPanelTop.add(qqPwd);
nbsp;nbsp;leftPanelTop.add(verify);
nbsp;nbsp;leftPanelTop.add(qqVer);
nbsp;nbsp;leftPanelBottom.setLayout(new GridLayout(1,2));
nbsp;nbsp;JLabel i_vc = new JLabel(new ImageIcon("images/VerificationCode.jpg"));//这是显示验证码的标签,帮你写好了,后面直接调用即可。
nbsp;nbsp;JButton bt1 = new JButton("帐号密码登陆");
nbsp;nbsp;JButton bt2 = new JButton("带验证码登陆");
nbsp;nbsp;JPanel btPanel = new JPanel();
nbsp;nbsp;btPanel.setLayout(new GridLayout(2,1));
nbsp;nbsp;btPanel.add(bt1);
nbsp;nbsp;btPanel.add(bt2);
nbsp;nbsp;leftPanelBottom.add(i_vc);
nbsp;nbsp;leftPanelBottom.add(btPanel);
nbsp;nbsp;//============================================
nbsp;nbsp;add(leftPanel);//将左面板放入窗体中
nbsp;nbsp;//右面板
nbsp;nbsp;JPanel rightPanel = new JPanel();
nbsp;nbsp;rightPanel.setBorder(BorderFactory.createTitledBorder("发表iPhone说说"));//给右面板加上边框,并添加文字
nbsp;nbsp;//========================请在下面写上你的代码
nbsp;nbsp;JTextArea msg = new JTextArea();
nbsp;nbsp;JButton submit = new JButton("马上发表说说");
nbsp;nbsp;rightPanel.setLayout(new BorderLayout());
nbsp;nbsp;rightPanel.add(msg, BorderLayout.CENTER);
nbsp;nbsp;rightPanel.add(submit, BorderLayout.SOUTH);
nbsp;nbsp;//============================================
nbsp;nbsp;add(rightPanel);//将右面板放入窗体中
nbsp;nbsp;setVisible(true);//使窗体可见
nbsp;}
nbsp;public static void main(String[] args){
nbsp;nbsp;new Login();
nbsp;}
}
登陆界面的java代码怎么写?
概述
具体框架使用jframe,文本框组件:JTextField;密码框组件:JPasswordField;标签组件:JLabel;复选框组件:JCheckBox;单选框组件:JRadioButton;按钮组件JButton。
登录界面:
代码实例
import javax.swing.*;
import java.awt.*; //导入必要的包
public class denglu extends JFrame{
JTextField jTextField ;//定义文本框组件
JPasswordField jPasswordField;//定义密码框组件
JLabel jLabel1,jLabel2;
JPanel jp1,jp2,jp3;
JButton jb1,jb2; //创建按钮
public denglu(){
jTextField = new JTextField(12);
jPasswordField = new JPasswordField(13);
jLabel1 = new JLabel("用户名");
jLabel2 = new JLabel("密码");
jb1 = new JButton("确认");
jb2 = new JButton("取消");
jp1 = new JPanel();
jp2 = new JPanel();
jp3 = new JPanel();
//设置布局
this.setLayout(new GridLayout(3,1));
jp1.add(jLabel1);
jp1.add(jTextField);//第一块面板添加用户名和文本框
jp2.add(jLabel2);
jp2.add(jPasswordField);//第二块面板添加密码和密码输入框
jp3.add(jb1);
jp3.add(jb2); //第三块面板添加确认和取消
// jp3.setLayout(new FlowLayout()); //因为JPanel默认布局方式为FlowLayout,所以可以注销这段代码.
this.add(jp1);
this.add(jp2);
this.add(jp3); //将三块面板添加到登陆框上面
//设置显示
this.setSize(300, 200);
//this.pack();
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
this.setTitle("登陆");
}
public static void main(String[] args){
new denglu();
}
}
拓展内容
java swing包
Swing 是一个为Java设计的GUI工具包。
Swing是JAVA基础类的一部分。
Swing包括了图形用户界面(GUI)器件如:文本框,按钮,分隔窗格和表。
Swing提供许多比AWT更好的屏幕显示元素。它们用纯Java写成,所以同Java本身一样可以跨平台运行,这一点不像AWT。它们是JFC的一部分。它们支持可更换的面板和主题(各种操作系统默认的特有主题),然而不是真的使用原生平台提供的设备,而是仅仅在表面上模仿它们。这意味着你可以在任意平台上使用JAVA支持的任意面板。轻量级组件的缺点则是执行速度较慢,优点就是可以在所有平台上采用统一的行为。
概念解析:
JFrame – java的GUI程序的基本思路是以JFrame为基础,它是屏幕上window的对象,能够最大化、最小化、关闭。
JPanel – Java图形用户界面(GUI)工具包swing中的面板容器类,包含在javax.swing 包中,可以进行嵌套,功能是对窗体中具有相同逻辑功能的组件进行组合,是一种轻量级容器,可以加入到JFrame窗体中。。
JLabel – JLabel 对象可以显示文本、图像或同时显示二者。可以通过设置垂直和水平对齐方式,指定标签显示区中标签内容在何处对齐。默认情况下,标签在其显示区内垂直居中对齐。默认情况下,只显示文本的标签是开始边对齐;而只显示图像的标签则水平居中对齐。
JTextField –一个轻量级组件,它允许编辑单行文本。
JPasswordField – 允许我们输入了一行字像输入框,但隐藏星号(*) 或点创建密码(密码)
JButton – JButton 类的实例。用于创建按钮类似实例中的 "Login"。
如何写网页登陆界面的代码
这个是处理表单的页面,其实如果按照你说的,只有一个用户名的话,那就不用数据库咯。满简单的。
%
AdminName=request("AdminName")
Password=request("Password")
if AdminName"制作" then
response.write"SCRIPT language=JavaScriptalert('用户名不正确!');"
response.write"javascript:history.go(-1)/SCRIPT"
else
response.redirect"qindayuan.com/vcckxp/215165.htm"
end if
if Password"0123456789" then
response.write"SCRIPT language=JavaScriptalert('密码错误!');"
response.write"javascript:history.go(-1)/SCRIPT"
else
response.redirect"qindayuan.com/vcckxp/215165.htm"
end if
%
这样子你试试看,表单的用户名文本框name用AdminName表示,密码用password。试试看吧,如果你觉得这代码不好的话,不用评答案也行,我只是给你一个参考。
登陆窗口代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于窗体登录界面代码、登陆窗口代码的信息别忘了在本站进行查找喔。
版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;
相关推荐
取消回复欢迎 你 发表评论:
- 标签列表
- 最近发表
- 友情链接