今日所做
-
新增了简单的管理员表
-
新增了管理员登录的功能
package web;
import dao.UserDao;
import domain.AdminUser;
import domain.User;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
@WebServlet("/dengluServlet")
public class dengluServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
String rand = (String) request.getSession().getAttribute("rand");
String username = request.getParameter("user");
String pwd = request.getParameter("pwd");
String randcode = request.getParameter("randcode");
UserDao dao = new UserDao();
int num_user = 0,num_admin = 0;
User user = null;
AdminUser adminUser = null;
if (!randcode.equals(rand)){
response.getWriter().write("<script>alert('验证码错误!');window.location.href='"+request.getContextPath()+"/login.html'</script>");
}
//查找是否有账号、以及登录
try {
num_user= dao.ajaxUsername(username);
num_admin = dao.ajaxAdminUser(username);
user = dao.login(username,pwd);
adminUser = dao.adminLogin(username,pwd);
} catch (SQLException e) {
e.printStackTrace();
response.getWriter().write("<script>alert('登录失败!');window.location.href='"+request.getContextPath()+"/login.html'</script>");
}
//登录逻辑处理
if (num_user == 0){
//用户名不存在,从管理员表中查询
if (num_admin == 0){
//没有该管理员账号
response.getWriter().write("<script>alert('该用户不存在,请注册!');window.location.href='"+request.getContextPath()+"/register.html'</script>");
}else {
if (adminUser != null){
//管理员登录成功
request.getSession().setAttribute("user",adminUser);
request.getSession().setAttribute("who","admin");
response.getWriter().write("<script>alert('登录成功!');window.location.href='"+request.getContextPath()+"/main.html'</script>");
}else if (adminUser == null){
//管理员账号或密码错误
response.getWriter().write("<script>alert('用户名或密码错误!');window.location.href='"+request.getContextPath()+"/register.html'</script>");
}
}
}else {
if (user != null){
//账号密码正确
request.getSession().setAttribute("user",user);
request.getSession().setAttribute("who","user");
response.getWriter().write("<script>alert('登录成功!');window.location.href='"+request.getContextPath()+"/main.html'</script>");
}else if (user == null ){
//账号密码错误
response.getWriter().write("<script>alert('用户名或密码错误!');window.location.href='"+request.getContextPath()+"/register.html'</script>");
}
}
}
}
-
新增了用户管理界面
-
新增了角色管理界面
- 新增了网络审核界面
明日计划
- 完成角色管理功能
- 完成新增角色功能
- 完成用户管理功能