导航:首页 > 编程语言 > java中用户注册的代码

java中用户注册的代码

发布时间:2022-01-19 20:58:08

1. 用户注册代码

我这有个,用的数据库是Oracle数据库 import java.awt.Dimension;
import java.awt.HeadlessException;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField; public class Entry{
private JFrame jf;
private JLabel label[]=new JLabel[2];
private JTextField user=new JTextField();
private JPasswordField pwd=new JPasswordField();
private JButton button[]=new JButton[2];
private Socket soc;
private static ObjectInputStream ois;
private static ObjectOutputStream oos;

//初始化窗口
public Entry() {

try {
soc=new Socket("127.0.0.1",8800);
InputStream is=soc.getInputStream();
ois=new ObjectInputStream(is);
OutputStream os=soc.getOutputStream();
oos=new ObjectOutputStream(os);
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

jf=new JFrame("Mye QQ");
jf.setLayout(null);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setSize(180,350);
Dimension screen=Toolkit.getDefaultToolkit().getScreenSize();
int left=(screen.width-jf.getWidth())/2;
int top=(screen.height-jf.getHeight())/2;
jf.setLocation(left, top);

}
//实例化登录输入框
public void loginStream(){
String string[]={"ID","密码"};
String string2[]={"登录","注册"};
for(int i=0,y=60,z=20;i<2;i++,y+=30,z+=70){
label[i]=new JLabel(string[i]);
label[i].setBounds(20,y,40,20);
jf.getContentPane().add(label[i]);
button[i]=new JButton(string2[i]);
button[i].setBounds(z,140,60,20);
jf.getContentPane().add(button[i]);
}

user.setBounds(70,60,80,20);
jf.getContentPane().add(user);
pwd.setBounds(70,90,80,20);
pwd.setEchoChar('*');
jf.getContentPane().add(pwd);
}

public static void main(String args[]){
final Entry enter=new Entry();
System.out.println("运行");
enter.loginStream();
enter.button[0].addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
enter.validate(enter);
}
});

enter.button[1].addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
new Registar(ois,oos);
}
});
enter.jf.setVisible(true);
}

//验证
public void validate(Entry en){
try {
String id=user.getText();
String password=new String(pwd.getPassword());
Client customer=new Client(id,password);
oos.writeObject(customer);
oos.flush();
//接收服务器发回的消息
Object o;
o = ois.readObject();
if (o instanceof Message) {
Message m=(Message)o;
if(m.getType()==5){
new ChatRoom(m.getFromName(),ois,oos);
jf.dispose();
}
else if(m.getType()==6){
JOptionPane.showMessageDialog(null,"请输入正确的ID和密码!","错误信息",JOptionPane.INFORMATION_MESSAGE);
user.setText(null);
pwd.setText(null);
}
}
} catch (HeadlessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

2. 跪求【JAVA】登陆 + 注册界面的代码......!!!

这个得连数据库,你的是什么数据库,C/S还是B/S的

3. 用java写只让用户注册三个用户名的代码

提供一个思路吧:
每次注册的时候,使用ajax到后台查询数据库中的数据,看看用户是否已经注册三个用户了,如果是,那就不允许用户再注册了。
如果没有达到三个用户就允许用户注册。

4. java ee用户注册代码

登陆界面:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My jsP 'UserLogin.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<style type="text/css">
body{
background: url(image/background1.jpg);
background-repeat:repeat;
margin:0 auto;
}
#id1{
margin-top:100px;
margin-left:500px;;
width:500px;
height:300px;
font-size:30px;
font-weight: bold;
}
.p1{
font-size:60px;
font-weight:bold;
color:maroon;
margin-left:50px;
margin-top:50px;
font-family: fantasy;
font-style: italic;
}
.ret1{
margin-top:20px;
margin-left:80px;
font-size:25px;
font-weight: bold;
}
.sub1{
margin-top:20px;
font-size:25px;
font-weight: bold;
}
.text1{
width:200px;
height:30px;
}
.text2{
width:220px;
height:30px;
}

</style>
</head>

<body>
<p class="p1">欢迎来到登录系统</p>
<div id="id1">
<form action="dealJspText.jsp" method="post" >
用户名:<input type="text" name="username" class="text1"/><br/>
密码: <input type="password" name="password" class="text2"/><br/>
<input type="submit" value="登录" class="sub1"/>
<input type="reset" value="重置" class="ret1"/>
</form>
</div>
</body>
</html>
后台处理,dealJspText.jsp文件
<%@ page language="java" import="java.util.*,java.sql.*"
pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'dealJspText.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

</head>

<body>
<%
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
String sql = "";
boolean isIn = false;
%>

<%
sql = "select * from userinformation";
//sql server 2008和jsp建立连接
//1.加载驱动
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
//建立连接
conn = DriverManager.getConnection(
"jdbc:sqlserver://localhost:1433;databaseName=liuyan",
"sa", "3209554");
//向数据库发送指令
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();//得到结果集合

//获取用户信息
String user = new String(request.getParameter("username").getBytes("ISO-8859-1"),"utf-8");
String password = request.getParameter("password");

session.setAttribute("name", user);
//判断该用户是否存在于数据库中
while (rs.next()) {
String string1 = rs.getString(1);
String string2 = rs.getString(4);
if (user.equals(string1)) {
if (string2.equals(password)) {
isIn = true;//表示该用户存在与数据库中
break;//如果存在则跳出整个循环
}
}
}
//这样就可以存入每一行的用户信息数据
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
rs.close();
pstmt.close();
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
}
%>
<%
if(isIn){
response.sendRedirect("user.jsp");//跳转到这个页面
}
else{
response.sendRedirect("error.jsp");//跳转到密码或用户名错误页面
}
%>
</body>
</html>
不懂得可以再来问我

5. 谁能写出JAVA中用户登陆的代码

import java.awt.*;
import javax.swing.*;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import db.DBAccess;
import java.sql.ResultSet;
import java.sql.*;
public class login extends JFrame {
DBAccess da=new DBAccess();
public login() {
try {
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
private void jbInit() throws Exception {
getContentPane().setLayout(null);
jLabel3.setText("用户名");
jLabel3.setBounds(new Rectangle(50, 67, 89, 40));
uname.setBounds(new Rectangle(176, 67, 106, 37));
upwsd.setBounds(new Rectangle(170, 119, 106, 37));
jToggleButton1.setText("取消");
jToggleButton1.setBounds(new Rectangle(184, 214, 96, 32));
jToggleButton1.addActionListener(new login_jToggleButton1_actionAdapter(this));
jToggleButton2.setText("登陆");
jToggleButton2.setBounds(new Rectangle(39, 214, 96, 32));
jToggleButton2.addActionListener(new login_jToggleButton2_actionAdapter(this));
this.getContentPane().add(uname);
this.getContentPane().add(upwsd);
this.getContentPane().add(jToggleButton1);
this.getContentPane().add(jToggleButton2);
this.getContentPane().add(jLabel3);
this.getContentPane().add(jLabel2);
jLabel2.setText("密码");
jLabel2.setBounds(new Rectangle(47, 116, 89, 40));
}

JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JTextField uname = new JTextField();
JTextField upwsd = new JTextField();
JToggleButton jToggleButton1 = new JToggleButton();
JToggleButton jToggleButton2 = new JToggleButton();
public void jToggleButton1_actionPerformed(ActionEvent e) {
this.dispose();

}

public void jToggleButton2_actionPerformed(ActionEvent e) {
String name=uname.getText();
String pwsd=upwsd.getText();

try {
ResultSet rs = da.getResultSet("select * from login where name='" +
name + "' and pwsd='" + pwsd + "'");

if(rs.next())
{
JOptionPane.showConfirmDialog(this,"登陆成功");
}
else
{
JOptionPane.showConfirmDialog(this,"登陆失败");
}
} catch (SQLException ex) {
ex.printStackTrace();
}
}
}
class login_jToggleButton2_actionAdapter implements ActionListener {
private login adaptee;
login_jToggleButton2_actionAdapter(login adaptee) {
this.adaptee = adaptee;
}

public void actionPerformed(ActionEvent e) {
adaptee.jToggleButton2_actionPerformed(e);
}
}

class login_jToggleButton1_actionAdapter implements ActionListener {
private login adaptee;
login_jToggleButton1_actionAdapter(login adaptee) {
this.adaptee = adaptee;
}

public void actionPerformed(ActionEvent e) {
adaptee.jToggleButton1_actionPerformed(e);
}
}

6. java中要求用户输入的代码

你的程序的问题,一个是数组arr1还没有输入完全就比较是否有重复字符串,是比较不出来的,二是字符串比较内容是否相同要用equals函数而不是用双等号==.
你的Java程序我帮你改好了,你看看吧.

package找重复;
publicclassstring{
publicstaticvoidmain(String[]args){
System.out.println("请输入5个字符串:");
String[]arr1=newString[5];
java.util.Scannersc=newjava.util.Scanner(System.in);
for(inti=0;i<arr1.length;i++){
arr1[i]=sc.nextLine();
}
for(inti=0;i<arr1.length;i++){
for(intj=i+1;j<arr1.length;j++){
if(arr1[i].equals(arr1[j])){
System.out.println(arr1[i]);
}
}
}
}
}

运行结果
请输入5个字符串:
we
are
the
world
the
the

7. JAVA用户注册 (我要源代码)

跑这儿作家庭作业了? 如果连用哪种页面技术都不知道提的话,恐怕别人给你源代码你也看不懂哦,想想别人给你个tapestry、Wicket之类的写的代码,拿给老师肯定挨批的哟(一看就露馅了)。

8. 求一JAVA图书管理系统的用户注册代码

struts里面有一个验证框架 用那个做就可以了啊 不要想的太复杂了

注册 就是给数据库的用户表 添加账号和密码

然后登陆 就是跟数据库用户表里面的账号和密码匹配 true就登陆 false 就登陆失败

9. java用户注册界面实现,下面代码哪错了呢

package wyf.jc;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class child extends JFrame implements ActionListener
{
private JPanel jp=new JPanel();
private JLabel[] jlArray={
new JLabel("用户名"),new JLabel("密码");
new JLabel("确认密码"),new JLabel("电子邮箱");
new JLabel("")
};

改成这样,下面不变

10. 用JAVA编写一个用户或注册登录界面。请哪位高手能够写下具体的代码,谢谢

  1. 效果图

    <!DOCTYPEhtml>
    <html>
    <head>
    <metacharset="UTF-8">
    <title>先锋图书馆管理系统-登录</title>
    <style>
    *{
    margin:0;
    padding:0;
    list-style:none;
    }
    #top{
    width:1000px;
    height:95px;
    margin:0auto;
    margin-top:25px;
    }
    #top_top{
    width:1000px;
    height:65px;
    background:deepskyblue;
    }
    #top_top_left{
    width:300px;
    height:65px;
    float:left;
    }
    #top_top_left>label{
    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:0auto;
    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>#login>img{
    float:left;
    }
    #content>#login>#select{
    width:305px;
    height:210px;
    float:right;
    }
    #content>#login>#select>div{
    width:230;
    height:30px;
    margin-left:30px;
    }
    #content>#login>#select>#d1{
    margin-top:30px;
    margin-bottom:3px;
    }
    #content>#login>#select>p{
    font-size:14px;
    margin-left:95px;
    }
    #bottom{
    width:1000px;
    height:35px;
    line-height:35px;
    margin:0auto;
    background:deepskyblue;
    text-align:center;
    color:white;
    }
    </style>
    </head>
    <body>
    <divid="top">
    <divid="top_top">
    <divid="top_top_left">
    <imgsrc="img/test/a13.png"width="78px"height="65px"><labelid="a2">先锋图书馆系统管理平台</label>
    </div>
    </div>
    <divid="top_bottom">
    <divid="top_bottom_left">当前位置:首页>系统管理>登录</div>
    <divid="top_bottom_right">当前时间:<labelid="lable"></label></div>
    </div>
    </div>
    <divid="content">
    <divid="text">欢迎登录先锋图书馆管理系统</div>
    <divid="login">
    <imgsrc="img/test/a14.png"width="175px"height="210px"/>
    <formid="select">
    <divid="d1">用户名:&nbsp;&nbsp;<inputtype="text"/></div>
    <div>密&nbsp;码:&nbsp;&nbsp;<inputtype="password"/></div>
    <p>
    <inputtype="radio"name="user"value="read"/>读者&nbsp;&nbsp;&nbsp;&nbsp;
    <inputtype="radio"name="user"value="admin"/>管理员
    </p><br/>
    <p>
    <inputtype="button"value="确定"style="width:50px;"onclick="put()"/>&nbsp;&nbsp;&nbsp;&nbsp;
    <inputtype="reset"value="重置"style="width:50px;"/>
    </p>
    </form>
    </div>
    </div>
    <divid="bottom">欣欣科技有限公司版权所有</div>
    </body>
    <scripttype="text/javascript"src="JQuery/jquery.js"></script>
    <scripttype="text/javascript"src="js/GetCurrentTime.js"></script>
    <script>
    //验证用户名和密码
    functionput(){
    vard=$("#select>div>input");//获取用户名和密码
    varname=d[0].value;
    varpass=d[1].value;
    varuser=null;
    varr=document.getElementsByName("user");//获取用户类型
    for(i=0;i<r.length;i++){
    if(r[i].checked){
    user=r[i].value;
    }
    }
    //console.log(name+","+pass+","+user);//输出测试
    if(user==null){
    window.alert("请选择用户类型!");
    }elseif(user=="admin"&&name!="admin"){
    window.alter("用户名错误!");
    }elseif(user=="admin"&&name=="admin"&&pass!="123456"){
    window.alert("密码错误!");
    }elseif(name=="admin"&&pass=="123456"&&user=="admin"){
    window.location.href="work_02_welcome.html";//在js中在本页面中打开新链接
    }else{
    window.alert("用户名错误");
    }
    }
    </script>
    </html>

阅读全文

与java中用户注册的代码相关的资料

热点内容
香港3级鬼片 浏览:329
疫情数据怎么没有美国 浏览:720
苹果电影高清版下载地址 浏览:165
有一部电影女主角头发是绿金发的叫什么名 浏览:197
古代一女多男肉文 浏览:338
老武打片100部正片 浏览:450
换眼睛伦理电影 浏览:970
日本鸭子的电影 浏览:456
小说主角叫齐天的是什么小说 浏览:912
免费飞卢小说破解网站 浏览:820
网站免费观看 浏览:497
韩国李采潭拍过的爱情电影 浏览:328
古典武侠另类小说综合 浏览:111
有个叫艾米的是什么电影名字 浏览:597
linux硬件交互 浏览:208
用友软件考生文件夹在哪里 浏览:55
微信投票开发java 浏览:133
哪里可以看《永恒》泰国电影无删减 浏览:538
iphonefacetimewifi 浏览:632
桌面文件没有备份怎么恢复 浏览:207

友情链接