導航:首頁 > 編程語言 > 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中用戶注冊的代碼相關的資料

熱點內容
系統修復部分文件 瀏覽:653
電腦上文件格式怎麼改pdf 瀏覽:923
如何在伺服器上共享文件夾 瀏覽:960
有什麼好看的漫畫網站 瀏覽:507
斗羅單女主是寧榮榮 瀏覽:736
帶著現代武器打鬼子小說 瀏覽:566
大尺度男同裸露電影 瀏覽:513
雙女主同性戀電影泰劇 瀏覽:594
影院後排選不了 瀏覽:428
鳳梨蘋果筆游戲 瀏覽:826
下載一部電影大概多少GB 瀏覽:714
看yellow有哪些網址 瀏覽:523
李采潭和池恩瑞演的電影 瀏覽:900
php企業網站 瀏覽:429
360不是原版文件 瀏覽:527
舊版安卓酷狗音樂下載 瀏覽:391
數控用g75下料怎麼編程 瀏覽:948
張雪峰客串電影完整版 瀏覽:439
ps怎麼把另外一個文件圖層復制 瀏覽:735

友情鏈接