// 2. Servlet with Session Management @WebServlet("/login") public class LoginServlet extends HttpServlet protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException

// 5. Filter for Authentication @WebFilter("/*") public class AuthFilter implements Filter

static HikariConfig config = new HikariConfig(); config.setJdbcUrl("jdbc:mysql://localhost:3306/mydb"); config.setUsername("root"); config.setPassword("password"); config.setMaximumPoolSize(10); dataSource = new HikariDataSource(config);

public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException (session != null && session.getAttribute("user") != null)) chain.doFilter(req, res); else response.sendRedirect("login.html");