Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Any way to write html form data to file?

  1. #1
    Junior Member
    Join Date
    Jan 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default 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.

Similar Threads

  1. J2ME-Show RMS data in tabular form
    By Sunil Raghuvanshi in forum Java ME (Mobile Edition)
    Replies: 1
    Last Post: January 24th, 2011, 08:06 AM
  2. storing data using form
    By anupam.j2ee in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 27th, 2010, 10:43 AM
  3. Save form as .pdf file?
    By Taron in forum AWT / Java Swing
    Replies: 3
    Last Post: November 14th, 2010, 02:20 PM
  4. How to write to specific part of an html file using java
    By nasi in forum File I/O & Other I/O Streams
    Replies: 12
    Last Post: May 27th, 2010, 11:22 PM
  5. How to Write and Read Binary Data
    By neo_2010 in forum File Input/Output Tutorials
    Replies: 3
    Last Post: January 4th, 2010, 02:38 PM