Any way to write html form data to file?
So I'm doing an online survey of sorts. I have the following html code:
Do you think this song was written by a human or by a computer?<br />
<form name="input" action="o.jar" method="get">
<input type="radio" name="human" value="true" /> Written by human<br />
<input type="radio" name="human" value="false" /> Written by computer<br />
<input type="submit" value="Submit" />
</form>
I would like to write a java app, o.jar, that does the following:
If (human=="true") {
read a number from the file "count.dat" on the server;
increment that number;
writes it back to the file;
} Else Do Nothing;
This may be a noob question but I've never done any server-side java programming... Should I just use standard java file I/O to read and write data from the file? How do you go about getting the value of the html variable "human" into the java program?
Thanks in advance.
Re: Any way to write html form data to file?
First, you should use equals() rather than == when comparing strings. To get the submitted value, you retrieve the values using form submission (either through GET or POST which passes key/value pairs)....depending upon the context of the server this is done through the ServletRequest object, using the getParameter method.Lots of tutorials about this online that can do a much better job than I at explaining it. You can use standard I/O, however multiple requests might cause a concurrency issue with the file. Stick the info into a database and this issue is dealt with appropriately.
PS Had to look up the project...quite interesting.