java - 为什么登录成功后还是会出现“Incorrect account or password or user type”?
问题描述
我已经尝试过,但无法弄清楚为什么,如果有任何解决方案,感谢您的帮助JFrame
。
if (userInfo != null ) {
JOptionPane.showMessageDialog(null, "LoginSuccessful");
dispose();
new ChooseRoomFrame(userInfo,UserRoomDetails,UserDao).setVisible(true);
}
if(Staff != null & rdbtnStaff.isSelected()){
JOptionPane.showMessageDialog(null, "Login Successful");
dispose();
new StaffFrame(userInfo, UserRoomDetails,UserDao).setVisible(true);
}
if(user.isEmpty() & pwd.isEmpty()){
JOptionPane.showMessageDialog(null,"Please insert Username and Password");
}
else if(user.isEmpty()){
JOptionPane.showMessageDialog(null,"Please insert Username");
}
else if (pwd.isEmpty()){
JOptionPane.showMessageDialog(null,"Please insert Password");
}
else {
JOptionPane.showMessageDialog(null, "Incorrect account or password or user type");
}
解决方案
由于您正在检查密码或用户名是否为空,因此当用户和密码不为空时,将执行最后的 else 语句。
else {
JOptionPane.showMessageDialog(null, "Incorrect account or password or user type");
}
删除此 else 语句,您的代码将按预期工作。
这是因为您已经涵盖了一个或两个字段为空的情况。这意味着缺少 if 的最终 else 将在它们不为空时执行。
推荐阅读
- reactjs - 如何使用 ReactJs 操作组件的子组件?
- javascript - 在处理 DOM 之前从后台脚本获取数据到内容脚本
- php - Laravel 和 Guzzle fopen():找不到上传到服务器的文件
- ruby-on-rails - 添加 best_in_place 时未定义的方法“service_path”
- python - ValueError: int() 以 10 为底的无效文字:'0.50'(我无法理解关于此的其他帖子)
- python - plt.show() 命令后继续程序而不关闭所有窗口
- java - Spring动态注入泛型
- python - pandas.read_table 的阅读问题
- deep-learning - 训练时遇到的一个奇怪问题
- kotlin - 迭代数据类列表未按预期工作