-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFormData.java
39 lines (37 loc) · 1.31 KB
/
FormData.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package examples;
import io.vacco.murmux.Murmux;
import io.vacco.murmux.middleware.MxRouter;
public class FormData {
public static void main(String[] args) {
LoggerInit.apply();
new Murmux().rootHandler(
new MxRouter()
.get("/form", xc -> {
xc.commitHtml(
"<!DOCTYPE html>\n" +
"<html>\n" +
"<body>\n" +
"\n" +
"<h2>HTML Forms</h2>\n" +
"\n" +
"<form action=\"/register\" method=\"post\">\n" +
" <label for=\"fname\">Username:</label><br>\n" +
" <input type=\"text\" name=\"username\" placeholder=\"Your username\"><br>\n" +
" <label for=\"lname\">Email:</label><br>\n" +
" <input type=\"text\" name=\"email\" placeholder=\"Your E-Mail\"><br>\n" +
" <input type=\"submit\" value=\"Submit\">\n" +
"</form> \n" +
"</body>\n" +
"</html>"
);
})
.post("/register", xc -> {
var email = xc.getFormParam("email");
var username = xc.getFormParam("username");
// Process data
// Prints "E-Mail: john@gmail.com, Username: john"
xc.commitText("E-Mail: " + email + ", Username: " + username);
})
).listen(8080);
}
}