Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Writing the file to a webserver

 
Jithesh Kumar
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jithesh Kumar
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ServletContext.getRealPath is exactly the way to go.
 
Jithesh Kumar
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic