Beruflich Dokumente
Kultur Dokumente
DOCTYPE html>
2. <html>
3. <head>
4. <meta charset="ISO-8859-1">
5. <title>Insert title here</title>
6. </head>
7. <body>
8.
9. Sample login Example (try with username as "admin" and password as
"admin" without quart ) <br> <br>
10.
11. <form action="LoginController" method="post">
12.
13. Enter username :<input type="text" name="username"> <br>
14. Enter password :<input type="password" name="password"><br>
15. <input type="submit" value="Login">
16.
17.
18. </form>
19.
20. </body>
21. </html>
</web-app>
1. package com.candidjava;
2.
3. import java.io.IOException;
4. import javax.servlet.ServletException;
5. import javax.servlet.http.HttpServlet;
6. import javax.servlet.http.HttpServletRequest;
7. import javax.servlet.http.HttpServletResponse;
8.
9. /**
10. * Servlet implementation class LoginController
11. */
12. public class LoginController extends HttpServlet {
13.
14. protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
15. String un=request.getParameter("username");
16. String pw=request.getParameter("password");
17.
18. if(un.equals("admin") && pw.equals("admin"))
19. {
20. response.sendRedirect("success.html");
21. return;
22. }
23. else
24. {
25. response.sendRedirect("error.html");
26. return;
27. }
28. }
29.
30. }
success page
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <meta charset="ISO-8859-1">
5. <title>Insert title here</title>
6. </head>
7. <body>
8.
9.
10. Login success
11.
12. </body>
13. </html>
14. <!DOCTYPE html>
15. <html>
16. <head>
17. <meta charset="ISO-8859-1">
18. <title>Insert title here</title>
19. </head>
20. <body>
21. Invalid username or password
22. </body>
23. </html>