// DeltaServlet.java import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import delta.core.servlet.DeltaServlet; public class LoginServlet extends DeltaServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) { renderView("/login.jsp", request, response); } protected void doPost(HttpServletRequest request, HttpServletResponse response) { String username = request.getParameter("username"); String password = request.getParameter("password"); boolean isValidUser = userService.validateUser(username, password); if (isValidUser) { request.setAttribute("username", username); renderView("/welcome.jsp", request, response); } else { renderView("/error.jsp", request, response); } } } // login.jsp <html> <head> <title>Login</title> </head> <body> <form method="post"> <input type="text" name="username" placeholder="Username"/> <input type="password" name="password" placeholder="Password"/> <input type="submit" value="Login"/> </form> </body> </html> // welcome.jsp <html> <head> <title>Welcome</title> </head> <body> <h2>Welcome, ${username}!</h2> </body> </html> // error.jsp <html> <head> <title>Error</title> </head> <body> <h2>Invalid username or password</h2> </body> </html>


上一篇:
下一篇:
切换中文