|
1 | | -<!-- |
2 | 1 | /* |
3 | | - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
| 2 | +" * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
4 | 3 | * |
5 | 4 | * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved. |
6 | 5 | * |
|
38 | 37 | * only if the new code is made subject to such option by the copyright |
39 | 38 | * holder. |
40 | 39 | */ |
41 | | ---> |
| 40 | +package org.javaee7.servlet.security.form.based; |
42 | 41 |
|
43 | | -<%@page contentType="text/html" pageEncoding="UTF-8"%> |
44 | | -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" |
45 | | - "http://www.w3.org/TR/html4/loose.dtd"> |
| 42 | +import java.io.IOException; |
46 | 43 |
|
47 | | -<html> |
48 | | - <head> |
49 | | - <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> |
50 | | - <title>Form-Based Login Page</title> |
51 | | - </head> |
52 | | - <body> |
53 | | - <h1>Form-Based Login Page</h1> |
| 44 | +import javax.servlet.ServletException; |
| 45 | +import javax.servlet.annotation.WebServlet; |
| 46 | +import javax.servlet.http.HttpServlet; |
| 47 | +import javax.servlet.http.HttpServletRequest; |
| 48 | +import javax.servlet.http.HttpServletResponse; |
54 | 49 |
|
55 | | - <form method="POST" action="j_security_check"> |
56 | | - Username: <input type="text" name="j_username"> <p/> |
57 | | - Password: <input type="password" name="j_password" autocomplete="off"> <p/> |
58 | | - <input type="submit" value="Submit" name="submitButton"> |
59 | | - <input type="reset" value="Reset"> |
60 | | - </form> |
| 50 | +/** |
| 51 | + * @author Arun Gupta |
| 52 | + * @author Arjan Tijms |
| 53 | + */ |
| 54 | +@WebServlet("/LoginServlet") |
| 55 | +public class LoginServlet extends HttpServlet { |
| 56 | + |
| 57 | + private static final long serialVersionUID = 1L; |
| 58 | + |
| 59 | + @Override |
| 60 | + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
| 61 | + response.setContentType("text/html;charset=UTF-8"); |
| 62 | + |
| 63 | + response.getWriter().print( |
| 64 | + |
| 65 | + "<html>" + |
| 66 | + "<head>" + |
| 67 | + "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">" + |
| 68 | + "<title>Form-Based Login Page</title>" + |
| 69 | + "</head>" + |
| 70 | + |
| 71 | + "<body>" + |
| 72 | + "<form method=\"POST\" action=\"j_security_check\">" + |
| 73 | + "Username: <input type=\"text\" name=\"j_username\"> <p/>" + |
| 74 | + "Password: <input type=\"password\" name=\"j_password\"> <p/>" + |
| 75 | + "<input type=\"submit\" value=\"Submit\" name=\"submitButton\">" + |
| 76 | + "</form>" + |
| 77 | + "</body>" + |
| 78 | + "</html>" |
| 79 | + |
| 80 | + ); |
| 81 | + } |
61 | 82 |
|
62 | | - </body> |
63 | | -</html> |
| 83 | + @Override |
| 84 | + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
| 85 | + response.getWriter().print("my POST"); |
| 86 | + } |
| 87 | +} |
0 commit comments