资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

java中用户注册的代码 java用户注册登录界面代码

java注册用户名不能重复代码

首先,我们得明白用户登录使用什么登陆的,即用户在线的原理。这只是将用户的对象存放在了session中而已,然后再frame中进行调用,其他特定页面也进行直接引用就行。那么实现“挤下来”的功能就是让新生成的session有效,让原来存放用户的session失效就行。到此,大体思路已经有了。那怎么实现呢?

创新互联坚持“要么做到,要么别承诺”的工作理念,服务领域包括:网站建设、网站制作、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的赤城网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!

想要知道怎么实现,就必须要明白session存放用户对象的过程了。在用户登录之后,我们可以得到用户的对象user,而存放到session中需要执行session.setAttribute(key,value); 我们将用户的userId或是其他的唯一标识存为key,将用户对象存为值。这样就能随时随地调用唯一用户了。user存放的问题解决了,那相同 登录 时session废除的问题呢?

这个其实也不难,我们可以更具session的特性一样,用map进行存贮,将用户的标识存为key,而将其所对应的session存为value,那么当重复用户登录时,只需要取出对应的session,将其invalidate就行了。

至此,实现思路已经明了,聒噪了这么久,大家都急不可耐地想看代码了吧?以下是代码:

前置准备,jsp界面

界面很简单,只是一个简单的登录界面

form action ="%=request.getContextPath()%/UserWXPServlet" method = "post"

用户名šinput type = "text" name = "username"/br/

密码šinput type = "text" name = "password"/br/

input type = "submit" value ="提交"/

/form

成功后跳转页面

欢迎:${sessionScope.user.username}登陆!br/

我这没有写失败页面,大家可以自己写,失败页面也没什么好说的了

entity和登录的实现

user的javabean

private String username;

private String password;

public User() {

}

public User(String user, String password) {

super();

this.username = user;

this.password = password;

}

public String getUsername() {

return username;

}

public void setUsername(String username) {

this.username = username;

}

public String getPassword() {

return password;

}

public void setPassword(String password) {

this.password = password;

}

登录user的service实现方法,这里就不写dao和接口了,一切以简单为

public boolean dologin(User user){

Properties pro = new Properties();

InputStream is = UserWXPServlet.class.getClassLoader().getResourceAsStream("user_wxp.properties");

String password = null;

System.out.println(is+"---------"+pro);

if(user==null){

return false;

}

try {

pro.load(is);

password = pro.getProperty(user.getUsername());

if(user.getPassword()!=nulluser.getPassword().equals(password)){

System.out.println("登陆成功");

return true;

}

} catch (IOException e) {

e.printStackTrace();

}finally{

if(is!=null){

try {

is.close();

} catch (IOException e) {

e.printStackTrace();

}

}

}

return false;

}

登录成功返回true,失败则返回false。

用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="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="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="read"/读者nbsp;nbsp;nbsp;nbsp;

input type="radio" name="user" value="admin"/管理员

/pbr/

p

input type="button" value="确定" style="width: 50px;" onclick="put()"/nbsp;nbsp;nbsp;nbsp;

input type="reset" value="重置" style="width: 50px;"/

/p

/form

/div

/div

div id="bottom"欣欣科技有限公司版权所有/div

/body

script type="text/javascript" src="JQuery/jquery.js"/script

script type="text/javascript" src="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="work_02_welcome.html";//在js中在本页面中打开新链接

}else{

window.alert("用户名错误");

}

}

/script

/html

java代码写注册,注册完成后,怎么写提示注册成功

Java写提示注册成功的方法如下:

1、首先用户注册完成后,返回一个boolean值的变量;

2、利用Servlet类判断这个变量,如果为true,跳转到提示界面,提示用户注册成功,如果为false,跳转到提示界面,提示用户注册失败;

3、具体代码如下所示:

public class DemoServlet extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

String username = request.getParameter("username");

String usepwd= request.getParameter("usepwd");

boolean flag = Dao.register(username,usepwd);//注册方法

if(flag){

//提示注册成功

request.getRequestDispatcher("/success.jsp").forward(request, response);

}else{

//提示注册失败

request.getRequestDispatcher("/success.jsp").forward(request, response);

}

}

public void doPost(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

doGet(request, response);

}

}

4、至此,就完成了提示注册成功的功能。

用java写一个手机商城注册界面代码

这篇文章主要介绍了java通过JFrame做一个登录系统的界面完整代码示例,具有一定借鉴价值,需要的朋友可以参考下。

在java的JFrame内通过创建匿名对象的方式做登录界面

package com.sxt;

import java.awt.Container;

import java.awt.GridLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JPasswordField;

import javax.swing.JTextField;

public class LoginFrame extends JFrame{

JTextField txtname=new JTextField();

JPasswordField txtpass=new JPasswordField();

JButton bl=new JButton("登录");

JButton bg=new JButton("关闭");

//构造无参构造器把主要的方法放在构造器里,然后在main方法里面调

public LoginFrame(){

setBounds(25,25,250,250);

Container c = getContentPane();

c.setLayout(new GridLayout(4,2,10,10));

c.add(new JLabel("用户名"));

c.add(txtname);

c.add(new JLabel("密码"));

c.add(txtpass);

c.add(bl);

c.add(bg);

setDefaultCloseOperation(EXIT_ON_CLOSE);

setVisible(true);

//注意:此处是匿名内部类

bg.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e) {

// TODO Auto-generated method stub

System.exit(0);

}

}

);

//注意:此处是匿名内部类

bl.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e) {


网站题目:java中用户注册的代码 java用户注册登录界面代码
分享地址:http://cdkjz.cn/article/ddeojjd.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220