I have a question, i am writing a file depending upon the user's selection.
that is : If i select "abc" then i can download a file that contains relevant data with "abc" and there are various selection options.
something like this :
And then am providing an <a>tag link to download it from the specific location.
Here essentially am overwriting one file "Test.doc" over and over again .
Its working fine on the site and all but i have a question for you Experts
1] If multiple user log in and select different options what will happen will they both download the file containing the same data irrespective of what the other user have selected?
2] Shall I create a new file for every user, or will that be handled automatically by the servlet ?
3] If i keep on creating new files how should i get rid of them once they are not required ?
I am not considering to create a temp file .
Give me directions i do not want to end up writing a very very bad web application .
I think you are trying to solve the wrong problem. It seems you are trying to create a file on the server everytime the user requests some information. but if more than one person requests information at the same time, the routine fails because you can only have one file with that name.
Rather than trying to figure out a way to allow multiple users to create and download this file, I think you should look at doing this without creating a file at all.
When the user clicks on the link as you indicate, that should run a servlet. The servlet processes the information, sets the content-type to the type of data it will be sending, and then sends the data. In most cases, the content-type is set to 'text/html' and you return HTML code. But you can return any data as long as the content-type is set properly and the data matches that type.
There are any number of packages available that let you create word , PDF, and excel objects from within Java. Inside your servlet you set the content-type and the header to match what you are sending. You then write that object to the response output stream. Instead of writing the data to a file on the server, you send it directly to the user.
To the user it looks like they are downloading a file, when the file never actually existed. You generated it on the fly.
For reference, these are the parts of the servlet that you will need to set.
Set the content type to the correct value for what you are sending. In the header you can provide the filename that the user sees when the browser gets the data. The getOutputStream returns the stream that is going to the requestor. Just send your object there.
There is a lot more to this, but you should be able to find a lot of information on the web and piece it together to meet your needs.