The form element will send another request to the server when the user hits the submit button. You need to set up the connection handler to be able to tell when you're receiving that request as opposed to another, and then parse out the data (which could be in a couple different formats depending on how you configure the form element).
You can return the value from the handler function to print it in main.
The MDN page on the form element may be useful if you aren't familiar with HTML already
I don't remember if <button>s automatically becomes submit buttons inside a form ↩︎
Thanks for your reply. Can I ask what crates I can use to get it down? I found there are many crates like Rocket, yew, web_sys and so on, they are created for WasmAssembly. But I don't need WasmAssembly, I thought the situation I am meeting is much more simpler.
yew is a frontend framework, working in the same way as all the famous JS frameworks like React, Vue, Svelte, etc. yew runs in the browser of the user (compiled as web assembly), rendering a webpage.
web_sys are raw bindings for the browser APIs. yew relies on web_sys to access the browser APIs, i.e. for manipulating the DOM.
rocket is a web server. It runs on your server (no web assembly involved here, unless you are using a web assembly runtime on your server, like wasmtime or wasmer), serving data to a client (i.e. you typing the URL to your server in the address bar of your browser). Now the code you provided in your question is a very basic web server build with functionality from the standard library. Frameworks like rocket abstract a lot of boilerplate away from your so you can focus on writing the logic of your application, rather than having to worry about all the technical stuff, like parsing HTTP requests, TLS, routing, HTTP headers, multithreading, etc. There are many web server frameworks out there to choose from, like rocket, actix-web, axum or warp. For a small discussion which one we think is best, see this recent topic: