aspose file tools*
The moose likes I/O and Streams and the fly likes Writing the file to a webserver Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Writing the file to a webserver" Watch "Writing the file to a webserver" New topic
Author

Writing the file to a webserver

Jithesh Kumar
Ranch Hand

Joined: Mar 09, 2010
Posts: 46
Hello all,

i would like to write a file to the webservers directory...is it possible?

If i have a url in my webserver like this --http://localhost:8080/context/img
is it possible to write a file to the "img" folder ?

Thanks in advance,


regards,
jithesh
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19693
    
  20

It may be possible with the PUT method, but most of the time PUT and DELETE are not allowed. What you could do is write a little page with an <input type="file"> element that allows users to POST a file. Your server code (JSP, servlet, PHP) must then take the uploaded file and move it to your img folder.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Jithesh Kumar
Ranch Hand

Joined: Mar 09, 2010
Posts: 46
Rob Prime wrote: and move it to your img folder.


Thank you for responding.

I forget to mention that i have the inputstream which i want to write to the file. But my doubt is that how to get the
path for writing the file. The application will have its own path depending on where it is deployed.

Can we use something like getcontextpath or getRealpath or any other method is there to find the path?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19693
    
  20

ServletContext.getRealPath is exactly the way to go.
Jithesh Kumar
Ranch Hand

Joined: Mar 09, 2010
Posts: 46
Rob Prime wrote:ServletContext.getRealPath is exactly the way to go.


Thank you....

Whether the ServletContext.getRealPath() will work if i am using apache tomcat as web server. I read that it wont work if i deploy the application in
war format. is that correct? and if so, is there any workaround for that ?

Jithesh.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Writing the file to a webserver