版权声明:版权声明:本文为博主原创文章,未经博主允许不得转载,博客地址:http://blog.csdn.net/xpala https://blog.csdn.net/xpala/article/details/88891235
1.LoginServlet登陆失败将失败消息保存给一个request,并转发回登陆页面
try {
BeanUtils.populate(formUser, request.getParameterMap());
User dbuser;
try {
dbuser=userService.login(formUser);
request.getSession().setAttribute("loginUsername", dbuser.getUsername());
response.getWriter().write("登陆成功,3秒后进入主页");
response.setHeader("refresh", "3;url=" + request.getContextPath() + "/main.jsp");
} catch (UserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
request.setAttribute("message", e.getMessage());
request.getRequestDispatcher("/login.jsp").forward(request, response);
}
2.登陆页面上添加失败消息
<body>
<p>${message}</p>
<form action="${pageContext.request.contextPath}/LoginServlet" method="post">
<table border="1">
<tr>