
正文
java退出登陆代码 javaweb退出登录代码
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
java用户名与密码5次输入错误后自动退出代码
public String login() throws Exception {
String rand = (String) session.get("rand");
HttpServletRequest request = ServletActionContext.getRequest();
HttpServletResponse response = ServletActionContext.getResponse();
response.setCharacterEncoding("GBK");
PrintWriter out = response.getWriter();
if (rand.equals(inputrand)) {
if (userDao.login(user)) {
User u = userDao.getSingleUser(user.getUsername());
int ismanager = u.getIsmanager();
session.put("ismanager", ismanager);
String leftBar = menuDao.getLoginMenu(user.getUsername(),
ismanager);
session.put("allmenu", menuDao.getAllMenu());
session.put("loginname", user.getUsername());
session.put("loginpwd", user.getPassword());
session.put("leftbar", leftBar);
session.put("tip", tipDao.getUserTips(user.getUsername()));
return SUCCESS;
} else {
Integer count = (Integer) session.get("loginCount");
String str = "";
if (count != null) {
count++;
if (count = 2) {
String message = "登陆失败三次,关闭窗口";
str = "scriptalert('"
+ message
+ "');"
+ "window.open('','_top');window.opener=null;window.close();/script";
} else {
session.put("loginCount", count);
String message = "用户名或密码错误,请重新输入";
String link = "/login.jsp";
str = "scriptalert('" + message + "');"
+ "window.location.href='"
+ request.getContextPath() + "" + link
+ "'/script";
}
} else {
session.put("loginCount", 1);
String message = "用户名或密码错误,请重新输入";
String link = "/login.jsp";
str = "scriptalert('" + message + "');"
+ "window.location.href='"
+ request.getContextPath() + "" + link
+ "'/script";
}
out.println(str);
out.flush();
out.close();
return null;
}
} else {
String message = "验证码出错,请重新输入";
String link = "/login.jsp";
String str = "scriptalert('" + message + "');"
+ "window.location.href='" + request.getContextPath() + ""
+ link + "'/script";
out.println(str);
out.flush();
out.close();
return null;
}
}
相关问答
Q1: 用java编写一种登录框:密码正确则显示登陆成功,错误三次显示登陆失败然后退出.点退出则退出!求高手帮忙!
package com.win;
import com.lcq.*;
import com.lcq.data.DataOperator;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class Login extends JFrame implements ActionListener
{
//ALT +"/"
JLabel lbName=new JLabel("用户名");
JLabel lbPwd=new JLabel("密 码");
JTextField textName =new JTextField();
JPasswordField textPwd =new JPasswordField();
JButton btnOK=new JButton("确定");
JButton btnCancel =new JButton("取消");
public Login()
{
this.getContentPane().setBackground(Color.blue);
this.setTitle("登录窗体");
this.setSize(300, 200);
this.setResizable(false);
this.add(lbName);
lbName.setBounds(50,50,50,20);
btnOK.addActionListener(this); //注册监听器
btnCancel.addActionListener(this); //注册监听器
this.add(lbPwd);
lbPwd.setBounds(50, 70, 50, 20);
this.add(textName);
textName.setBounds(120, 50, 100, 20);
this.add(textPwd);
textPwd.setBounds(120, 70, 100, 20);
this.add(btnOK);
btnOK.setBounds(50, 100, 70, 20);
this.add(btnCancel);
btnCancel.setBounds(160, 100, 70, 20);
this.setLayout(null);
lbName.setForeground(Color.white);
lbPwd.setForeground(Color.white);
Dimension screenSize =
Toolkit.getDefaultToolkit().getScreenSize();
this.setLocation (screenSize.width / 2 - (this.getWidth() / 2),
screenSize.height / 2 - (this.getHeight() / 2));
}
@Override
public void actionPerformed(ActionEvent arg0) //事件处理方法
{
if(arg0.getSource().equals(btnOK))
{
int i=0;
do
{
String name=textName.getText();
String Pawd=new String( textPwd.getPassword());
if(name.equals("aaa")Pawd.equals("aaa"))
{
//System.out.println("登录成功!");
JOptionPane.showConfirmDialog(null, "登录成功!","提示",JOptionPane.DEFAULT_OPTION);
}
else
{
//System.out.println("用户名或密码错误!");
JOptionPane.showConfirmDialog(null, "用户名或密码错误!","提示",JOptionPane.DEFAULT_OPTION);//对话框
i=i+1;
if(i3)
{
JOptionPane.showConfirmDialog(null, "登录失败","提示",JOptionPane.DEFAULT_OPTION);
System.exit(0);
}
}
}while(true);
}
if(arg0.getSource().equals(btnCancel))
{
JOptionPane.showConfirmDialog(null, "你退出了系统!","提示",JOptionPane.DEFAULT_OPTION);
System.exit(0);
}
}
}
//这个是调用
package com.main;
import com.win.*;
public class Test {
/**
* @param args
*/
public static void main(String[] args)
{
Login lg=new Login();
lg.setVisible(true);
}
}
Q2: java ATM登陆循环代码?
下面是一个简单的登录示例:
代码复制展示:
public class ATMLogin {
public static void main(String[] args) {
// 设置用户名和密码
String username = "gqk";
String password = "520";
// 最多可以登录 3 次
for (int i = 0; i 3; i++) {
// 读取用户输入的用户名和密码
Scanner in = new Scanner(System.in);
System.out.print("请输入用户名:");
String inputUsername = in.nextLine();
System.out.print("请输入密码:");
String inputPassword = in.nextLine();
// 检查用户名和密码是否正确
if (inputUsername.equals(username) inputPassword.equals(password)) {
System.out.println("欢迎" + username + "登录!");
break; // 登录成功,退出循环
} else {
System.out.println("用户名或密码错误,请重新输入!");
}
}
// 如果 3 次登录都失败,则提示用户
System.out.println("卡片已经被锁,请联系客服人员!");
}
}
回答不易望请采纳
Q3: java语言如何实现 登陆 退出 功能
在一个纯java项目中,登录就是你从客户端收受账户和密码,和数据库中已有的键值对进行匹配,如果匹配顺利,就显示登录成功。接着后台向前台返回数据,跳转到相应的页面。匹配程序可以单独写一个类,或者在工具类中封装一个方法,传入前台发过来的数据,最后返回一个布尔值。
退出功能的实现,就是后台发送数据,直接退出当前账户。或者关闭客户端。
Q4: 实现 界面登陆 退出 功能的java代码杂写
CS结构系统的退出如下:public void init() {
this.setTitle("用户登录界面");
this.add(createCenterPane());
this.setDefaultCloseOperation(this.DO_NOTHING_ON_CLOSE);
this.setSize(new Dimension(450, 335));
this.setLocationRelativeTo(null);
// this.setVisible(true);
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
int choose = JOptionPane.showConfirmDialog(null, "是否要退出登录界面?",
"系统提示:", JOptionPane.YES_NO_OPTION);
if (choose == JOptionPane.YES_OPTION) {
System.exit(1);
}
}
});
}其中this为JFrame对象。BS结构的退出直接用windows.close()方法就行了!
Q5: 实现界面登陆,退出功能的java代码怎么写?
CS结构系统的退出如下:public void init() {
this.setTitle("用户登录界面");
this.add(createCenterPane());
this.setDefaultCloseOperation(this.DO_NOTHING_ON_CLOSE);
this.setSize(new Dimension(450, 335));
this.setLocationRelativeTo(null);
// this.setVisible(true);
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
int choose = JOptionPane.showConfirmDialog(null, "是否要退出登录界面?",
"系统提示:", JOptionPane.YES_NO_OPTION);
if (choose == JOptionPane.YES_OPTION) {
System.exit(1);
}
}
});
}其中this为JFrame对象。BS结构的退出直接用windows.close()方法就行了!
java退出登陆代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于javaweb退出登录代码、java退出登陆代码的信息别忘了在本站进行查找喔。








