java用户名与密码5次输入错误后自动退出代码
3个回答
展开全部
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 = "<script>alert('"
+ message
+ "');"
+ "window.open('','_top');window.opener=null;window.close();</script>";
} else {
session.put("loginCount", count);
String message = "用户名或密码错误,请重新输入";
String link = "/login.jsp";
str = "<script>alert('" + message + "');"
+ "window.location.href='"
+ request.getContextPath() + "" + link
+ "'</script>";
}
} else {
session.put("loginCount", 1);
String message = "用户名或密码错误,请重新输入";
String link = "/login.jsp";
str = "<script>alert('" + 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 = "<script>alert('" + message + "');"
+ "window.location.href='" + request.getContextPath() + ""
+ link + "'</script>";
out.println(str);
out.flush();
out.close();
return null;
}
}
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 = "<script>alert('"
+ message
+ "');"
+ "window.open('','_top');window.opener=null;window.close();</script>";
} else {
session.put("loginCount", count);
String message = "用户名或密码错误,请重新输入";
String link = "/login.jsp";
str = "<script>alert('" + message + "');"
+ "window.location.href='"
+ request.getContextPath() + "" + link
+ "'</script>";
}
} else {
session.put("loginCount", 1);
String message = "用户名或密码错误,请重新输入";
String link = "/login.jsp";
str = "<script>alert('" + 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 = "<script>alert('" + message + "');"
+ "window.location.href='" + request.getContextPath() + ""
+ link + "'</script>";
out.println(str);
out.flush();
out.close();
return null;
}
}
展开全部
加一个计数器,放入session 错误一次加一,第五次的时候退就可以了!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐于2016-06-16 · 知道合伙人数码行家
huanglenzhi
知道合伙人数码行家
向TA提问 私信TA
知道合伙人数码行家
采纳数:117538
获赞数:517181
长期从事计算机组装,维护,网络组建及管理。对计算机硬件、操作系统安装、典型网络设备具有详细认知。
向TA提问 私信TA
关注
展开全部
// The "Test" class.
import java.awt.*;
import hsa.Console;
public class Test
{
static Console c; // The output console
public static void main (String[] args)
{
c = new Console ();
String un;
String pw;
String fun = "XXXX";
String fpw = "YYYY";
//最多运行5次,通过i变量进行计数
for (int i = 0 ; i < 5 ; i++)
{
c.print ("UserName:");
un = c.readString ();
c.print ("Password:");
pw = c.readString ();
//当用户名和密码都对的话,退出运行
if (un.equals (fun) || pw.equals (fpw))
{
i = 3;
}
}
} // main method
} // Test class
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询