Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Servlet writing a file inside WEB-INF  RSS feed

 
Mahtab Alam
Ranch Hand
Posts: 391
1
Java MySQL Database PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want a servlet to write a file inside WEB-INF folder
I tried these things

File file =new File("feedback.txt");

or

File file =new File("/feedback.txt");

or

File file =new File("WEB-INF/feedback.txt");

 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Web apps do not have a default directory - you need to use absolute paths. ServletContext.getRealPath helps with that.
 
Mahtab Alam
Ranch Hand
Posts: 391
1
Java MySQL Database PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your reply helped me , now i am able to create file using real path.
But still its not writing data to that file , but it have created the file there.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're closing all Streams and Writers, right?
 
Mahtab Alam
Ranch Hand
Posts: 391
1
Java MySQL Database PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its writing now , I was giving wrong path .
Working fine .

Thank you Ulf
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65830
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I highly recommend against adding files into the context of the web app: what happens to these files when you next redeploy?
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The files might be just fine - deploying into the exploded war file structure (rather than having the servlet container unpack a war file) is not uncommon. But I agree with the sentiment - files should generally be stored outside of the app directory.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!