CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    May 2001
    Location
    Puerto Rico
    Posts
    26

    Tabulate a survey using a servlet & writing to a file

    Hi!!
    I need to develop a questionnaire and tabulate users' answers.
    I will use a servlet to process the questionnaire and write the answers to a file.
    Could someone give me info on how do I write to a file using servlets??
    Any new idea on how to develop my questionnaire is accepted!!

    Thanks a lot.

    JNP

  2. #2
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Re: Tabulate a survey using a servlet & writing to a file

    I think you can use the same classes to write to a file from a servlet as from any other java application.

    Norm
    Norm

  3. #3
    Join Date
    May 2001
    Location
    Puerto Rico
    Posts
    26

    Re: Tabulate a survey using a servlet & writing to a file

    I am having some problems appending to a file. I used

    FileWriter fout = new FileWriter(outputFile,true);



    to make the append.
    my code doesnt compiles.
    this is the code for the file tasks


    String outputFileName = "c:/text.txt";
    File outputFile = new File(outputFileName);
    FileWriter fout = new FileWriter(outputFile,true);
    FileWriter fout = new FileWriter(outputFile,true);
    fout.write("This will be the appended data");



    The error is the following:
    cuestionario.java [57:1] cannot resolve symbol
    symbol : constructor FileWriter (java.io.File,boolean)
    location: class java.io.FileWriter
    FileWriter fout = new FileWriter(outputFile,true);
    ^
    1 error
    Errors compiling cuestionario.

    Can you tell me what's wrong??
    Thanks

    JNP

  4. #4
    Join Date
    Apr 2000
    Location
    Paris, France
    Posts
    154

    Re: Tabulate a survey using a servlet & writing to a file

    Hi,

    I think it's pretty obvious what's wrong:
    the FileWriter class doesn't have a constructor which takes a File and boolean as arguments. You should pass the instead the file name and the boolean; the following code should compile


    FileWriter out = new FileWriter(outputFileName, true);




    regards,
    Claudiu

    Brainbench MVP for C++
    ICQ #: 65097130
    Make sure you rate the post if helped ! This encourage people to respond.

  5. #5
    Join Date
    May 2001
    Location
    Puerto Rico
    Posts
    26

    Re: Tabulate a survey using a servlet & writing to a file

    I solved the problem about appending to a file. Now I have all the user's answers on a file named respuestas.txt. I am completely stock here. I dont know how to tabulate the results. What I need is to determine how many persons answered a, how many answered b (as an example)... etc Please give me some ideas.

    JNP

  6. #6
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Re: Tabulate a survey using a servlet & writing to a file

    You'll have to do some problem analysis here.
    There are many solutions depending on what the data looks like and how you are able to read thru it.
    For example, have a loop that iterates thru all the persons and have a group of counters for the answers;
    In pseudo code:
    start loop:
    get next person
    if person answered ques_a
    ques_a_cnt++; // count
    if person answered ques_b
    ques_b_cnt++;
    ... etc
    end loop;

    Norm
    Norm

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured