1 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
|
---|
2 | pageEncoding="ISO-8859-1"%>
|
---|
3 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
---|
4 | <html>
|
---|
5 | <head>
|
---|
6 | <title>User Log in</title>
|
---|
7 | </head>
|
---|
8 | <body>
|
---|
9 | <center>
|
---|
10 | <fieldset style="width: 300px">
|
---|
11 | <legend> Login here </legend>
|
---|
12 | <table>
|
---|
13 | <tr>
|
---|
14 | <td>User name (required)</td>
|
---|
15 | <td><input type="text" id="name" name="username"
|
---|
16 | required="required" onchange="enteredname()" /></td>
|
---|
17 | </tr>
|
---|
18 | <tr>
|
---|
19 | <td>Password</td>
|
---|
20 | <td><input type="password" id="password" name="userpass"
|
---|
21 | onchange="enteredpass()" /></td>
|
---|
22 | </tr>
|
---|
23 | <tr>
|
---|
24 | <td><button onClick="login()">Log in</button></td>
|
---|
25 | </tr>
|
---|
26 | </table>
|
---|
27 | </fieldset>
|
---|
28 | <br> <br>
|
---|
29 | <table>
|
---|
30 | <tr>
|
---|
31 | <td>
|
---|
32 | <button>Register as new user</button> (enter your new name and mew
|
---|
33 | password above)
|
---|
34 | </td>
|
---|
35 | </tr>
|
---|
36 | <tr>
|
---|
37 | <td>
|
---|
38 | <button>Reset my password</button> (enter name above)
|
---|
39 | </td>
|
---|
40 | </tr>
|
---|
41 | </table>
|
---|
42 |
|
---|
43 | </center>
|
---|
44 |
|
---|
45 | <script>
|
---|
46 | "use strict";
|
---|
47 |
|
---|
48 | function getName() {
|
---|
49 | return document.getElementById('name').value
|
---|
50 | }
|
---|
51 |
|
---|
52 | function getPass() {
|
---|
53 | return document.getElementById('password').value
|
---|
54 | }
|
---|
55 |
|
---|
56 | function login() {
|
---|
57 | /* fetch("AccountServlet", {
|
---|
58 | method : "POST",
|
---|
59 | body: "hello"
|
---|
60 | }).then(
|
---|
61 | response => alert(response.text())
|
---|
62 | ).then(
|
---|
63 | html => console.log(html)
|
---|
64 | );
|
---|
65 | return; */
|
---|
66 |
|
---|
67 | var xmlHttp = new XMLHttpRequest();
|
---|
68 | xmlHttp.open("POST", "AccountServlet", true); // false for synchronous request
|
---|
69 | xmlHttp.setRequestHeader('Content-Type', "text/json");
|
---|
70 | xmlHttp.onreadystatechange = function() {
|
---|
71 | if (xmlHttp.readyState == 4) {
|
---|
72 | if (xmlHttp.status == 200) {
|
---|
73 | alert("logged in!");
|
---|
74 | } else {
|
---|
75 | alert("access denied!");
|
---|
76 | }
|
---|
77 | }
|
---|
78 | }
|
---|
79 | xmlHttp.send(JSON.stringify({
|
---|
80 | 'name' : getName(),
|
---|
81 | 'password' : getPass()
|
---|
82 | }));
|
---|
83 |
|
---|
84 |
|
---|
85 | }
|
---|
86 | </script>
|
---|
87 |
|
---|
88 | <noscript>Sorry, your browser does not support JavaScript!</noscript>
|
---|
89 | </body>
|
---|
90 | </html>
|
---|