HTML and CSS Reference
retrieving the results as you do for submitting the form in the first place.
Implementing this requires an additional level of indirection for both client and server. When the client submits
the form, do not immediately calculate the result and feed it back to them. Instead,
Process the user input.
Generate a response for the user and store it.
Assign a roughly random URL for the response.
Redirect the client to the response.
Of course, the details will depend on exactly how the form is normally processed. Processing the data submitted
from the form is usually the same as when responding directly. If you store the data in a database, it's still
stored in the database. If the input is e-mailed to someone, it's still e-mailed to someone. If it starts up a robot
on the factory floor, it still starts the same robot on the factory floor.
The trick is the next step. We do not form the response HTML document in memory and send it directly to the
client in the body of the HTTP response. Instead, we form the HTML and save it somewhere: in a database, on
the filesystem, on another server, or wherever is most convenient. Sometimes you'll save an actual complete
HTML document. Other times you'll just save data that can be filled into a template later. If your server is
mostly serving static HTML in the first place, static files are likely the simplest. If the server is database-backed
and template-driven, storing the data for later insertion in a template is probably easier. The client won't know
or care which approach you take.
Either way, you need to associate a URL with the data that can be used to find it later. If everything's in static
files, the actual URL of the file is likely enough. Just pick a random name for that file. If the data is stored in the
database, you'll probably need to add another table to map randomly chosen URLs to particular records. Either
way, when the request comes in, the server will match the URL to what is stored and send out the appropriate
Finally, you send the client a 300-level HTTP response redirecting them to this new data. In this case, 301
Moved Permanently is usually what you want. This server will also have a Location header that points to the
result document. For example, using Java servlets, some code along these lines would do the trick:
OutputStream out = response.getOutputStream();
Writer w = new OutputStreamWriter(out, "UTF-8");
"some HTML in case the browser doesn't follow the redirect");
PHP, RAILS, and other frameworks have similar abilities.