Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Writing files into WEB-INF

 
Brooke Maddox
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a method in a Java class that I would like to use to write to a text file which is located in my WEB-INF dir. I think I am having trouble getting the correct path for this file. I am calling the method in my Servlet and using Servlet Context in order to get the path but I have yet to write anything to the text file. Here is my code
Servlet

Class
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65220
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is a phenomenally bad idea to write anything into the web app folders.

What happens when you need to redeploy the app and all your changed/written files are wiped out?

Why are you doing this?
 
Brooke Maddox
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For my assignment I have to use a text file that I can read from and write to. I thought that putting it in the WEB-INF would keep it hidden from the user.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65220
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It will, but is unmaintainable. Writing it somewhere outside the web app ail also "hide it" from the user.
 
Brooke Maddox
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So do you suggest that I have a folder outside the WEB-INF that is dedicated to my .txt file? Can I put the .txt file in the same folder as my Bean or Class? Do I still need to use the getServletContext() in my Servlet?
 
Brooke Maddox
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got it! Thanks again Bear
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic