博主介绍:✌专注于Java技术领域和学生毕业项目实战,欢迎大家交流✌
主要内容:SpringBoot、Vue、SSM、HLMT、Jsp、PHP、Nodejs、Python、爬虫、数据可视化、小程序等设计与开发。
文末获取源码+数据库
感兴趣的可以先收藏起来,还有大家在毕设选题,项目以及论文编写等相关问题都可以给我留言咨询,希望帮助更多的人~~~
通过基于Java(SSM)的班级同学录网站管理系统,用户可以方便快捷地管理同学信息、参与校友活动、交流经验心得,实现了班级同学之间更好的沟通与联系。管理员则可以高效地管理系统的运营和用户信息,确保系统的正常运行。
@WebServlet("/login")
public class LoginServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String username = request.getParameter("username");
String password = request.getParameter("password");
// 根据用户数据库验证用户名和密码
if (isValidUser(username, password)) {
//登陆成功
request.getSession().setAttribute("username", username);
response.sendRedirect("dashboard.jsp"); // Redirect to the dashboard or another secure page
} else {
// 登录失败
response.sendRedirect("login.jsp?error=true");
}
}
private boolean isValidUser(String username, String password) {
// 实现逻辑来验证用户(例如,检查数据库)
// 如果用户有效则返回true,否则返回false
//这是一个基本示例
return "demo".equals(username) && "password123".equals(password);
}
}
@WebServlet("/logout")
public class LogoutServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// 使会话失效以注销用户
request.getSession().invalidate();
response.sendRedirect("login.jsp");
}
}
@WebServlet("/dashboard")
public class DashboardServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// 检查用户是否通过认证
if (request.getSession().getAttribute("username") == null) {
response.sendRedirect("login.jsp");
return;
}
// 显示仪表板
// 您的安全页面逻辑在这里
response.getWriter().println("Welcome to the dashboard, " + request.getSession().getAttribute("username"));
}
}
@WebServlet("/dashboard")
public class DashboardServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// 检查用户是否通过认证
if (request.getSession().getAttribute("username") == null) {
response.sendRedirect("login.jsp");
return;
}
// 显示仪表板
// 安全页面逻辑在这里
response.getWriter().println("Welcome to the dashboard, " + request.getSession().getAttribute("username"));
}
}
@WebServlet("/login")
public class LoginServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String username = request.getParameter("username");
String password = request.getParameter("password");
// 根据用户数据库验证用户名和密码
if (isValidUser(username, password)) {
//登陆成功
request.getSession().setAttribute("username", username);
response.sendRedirect("dashboard.jsp"); // Redirect to the dashboard or another secure page
} else {
// 登录失败
response.sendRedirect("login.jsp?error=true");
}
}
private boolean isValidUser(String username, String password) {
// 实现逻辑来验证用户(例如,检查数据库)
// 如果用户有效则返回true,否则返回false
//这是一个基本示例
return "demo".equals(username) && "password123".equals(password);
}
}
@WebServlet("/logout")
public class LogoutServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// 使会话失效以注销用户
request.getSession().invalidate();
response.sendRedirect("login.jsp");
}
}
@WebServlet("/dashboard")
public class DashboardServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// 检查用户是否通过认证
if (request.getSession().getAttribute("username") == null) {
response.sendRedirect("login.jsp");
return;
}
// 显示仪表板
// 您的安全页面逻辑在这里
response.getWriter().println("Welcome to the dashboard, " + request.getSession().getAttribute("username"));
}
}
@WebServlet("/dashboard")
public class DashboardServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// 检查用户是否通过认证
if (request.getSession().getAttribute("username") == null) {
response.sendRedirect("login.jsp");
return;
}
// 显示仪表板
// 安全页面逻辑在这里
response.getWriter().println("Welcome to the dashboard, " + request.getSession().getAttribute("username"));
}
}
私信或者加我好友即可**~~~**
✌欢迎大家点赞、收藏、关注、评论啦~~~✌
感兴趣的可以先收藏起来,还有大家在毕设选题,项目以及论文编写等相关问题都可以给我留言咨询,希望帮助更多的人~~~