A question on Servlet File I/O

reef_d

Disciple
Apr 2, 2005
267
0
0
38
Here's my problem:

I have a simple form with Name, Email and Message. If these fields are valid I write them to a text file. I want to work on the opposite now i.e. if the file exists with data, to populate the fields with the right data. So do i use BufferedReader methods? If so which methods should i use? Any other solution to this? Read character by character perhaps?
 

nukeu666

Skilled
Dec 19, 2006
2,156
45
112
40
with bufferedreader you can should the read method which gets the file line by line

then you can use the usual string manipulators
 

hammerhead

Adept
Jun 26, 2006
683
26
0
37
www.teamreflex.org
If you are writing the file as comma delimited value (or any other character) then you can extract the line you want and then use the String.split() method to extract the contents. Once you have them, simply populate them in the HTML tags using the value field.
 

reef_d

Disciple
Apr 2, 2005
267
0
0
38
I think i'll use String Tokenizer for it. Thanks anyway.

Also another question I have, if my display servlet or html file has two submit buttons, how do i call different servlets/java class files for each submit button.

For example my file has a 'Submit', 'Save' and 'Retrieve' button.
 

reef_d

Disciple
Apr 2, 2005
267
0
0
38
isn't the action parameter part of the < FORM >??

If you do have any solution, let me know. Thanks for your help
 

reef_d

Disciple
Apr 2, 2005
267
0
0
38
Here's what I want to do to extend functionality

Code:
# Create invitations as HTML files for invitees; the invitations should include invitation text

So would I have to redirect each user to a new servlet with the html encoding. Any better solutions?
 

hammerhead

Adept
Jun 26, 2006
683
26
0
37
www.teamreflex.org
reef_d said:
Here's what I want to do to extend functionality

Code:
# Create invitations as HTML files for invitees; the invitations should include invitation text

So would I have to redirect each user to a new servlet with the html encoding. Any better solutions?

Creating a servlet for each user would be the worst way of approaching this probelem. Remember that JSP/Servlets fall into the category of dynamic web programming, meaning that you can generate different HTML content for different users in the same Servlet/JSP.

If you already have a list of users present in a database or file, then in a servlet simply validate the credintials of a user and in the servlet use the out.println() statement to display his details.
 

reef_d

Disciple
Apr 2, 2005
267
0
0
38
Thanks man, appreciate the help. I'm taking a class on Web Programming and I've read up on MVC and stuff so I'm finding the basic servlets part really annoying. I guess it's required for a good base, but I just find it annoying. Do things like EJB, Spring etc. make things easier after knowing servlets?
 

reef_d

Disciple
Apr 2, 2005
267
0
0
38
Yeah, I'm looking forward to JSP. I'm more of a PHP programmer when it comes to the Web but working a lot in Java in my research so, trying to pick up all round skills in it.
 

reef_d

Disciple
Apr 2, 2005
267
0
0
38
Code:
Here's my problem of sorts:

I have a csv file with Name, Email, Binary value( Yes/No)

I have to scan the csv and for all usernames with value 'No', I have to create an html page with the values in it.

Then I have to update the file changing the binary from No to Yes.

So basically, the updating part is done, but i'm stuck on the whole filereading part. How do i scan a file with multiple entries and search for all entries with the 'No' value through it. If I get through that stage, then creating an html file won't be all that hard.

My file I/O concepts really poor especially since I've been using Databases more often.