A question on Servlet File I/O

reef_d

Disciple
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?
 
with bufferedreader you can should the read method which gets the file line by line

then you can use the usual string manipulators
 
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.
 
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.
 
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?
 
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.
 
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?
 
Dont know about spring, but EJB's do not make things easier. JSP's on the other hand make web programming very simple and that is the next step you should take after learning Servlets.
 
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.
 
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.
 
Back
Top