I have some text from a text area from the html, this needs to be stored in a file on the webserver, any tips on how to go about it. I have no problems doing this locally, and i know how to use the class File etc..
It's no different on a webserver than on a local machine. The trick is knowing where to write the file.
I recommend using a context-init-param or a servlet-init-param to configure the path. Trying to use the current working dir or trying to dynamically determine the location of the webapp itself are recipies for headaches.
Originally posted by Zein Nunna: What do i need to do with the context-init-param or a servlet-init-param? What i am trying to do is have a directory structure something like /uni/var1/var2/file.txt Where uni is an existing directory an var1 and var2 are varibles that I will retrieve via request.getParameter(....);
I mentioned configuring the file's path on the server as an init-param because a j2ee app will not exist on the file system if it is run from a packed war file. ServletContext.getRealPath("/") will return null. If you plan on deploying to a container that allows you to run from an exploded file system and you don't care about portability then there is no need to concern yourself with this issue.
Joined: Mar 31, 2005
Thanks for the advice above.
I dont think i'll be needing a .war file, the app will run from just my computer, and i just need to demonstarte once - and after that it will probably not be used.
RE: the issue above, well it kinda works, but doesnt work at the same time.
I have a servelet that creates a directory structure, using method as follows:
Locally this works fine.
In the servlet I have an if statement (as shown below) which directs me to different sites depending on if the directory structure exists or not.
if (new File(/test/one).mkdirs()) Site A else Site B
So the 1st time round, it should be site A and then subsequent times site B, this works as it should, however the directory structre isnt visible in my root directory, sooo where is it then? I know its being created (due to the if statements)?