0

so i have a war deployed, and i need to make a temp file. but when i make one in the java app it creates it in the tomcat root which is not equal to the web root... how do i create a tmp file in the root if i dont know where the application is executing from in relation to the tomcat root?

-M

3
Contributors
3
Replies
4
Views
9 Years
Discussion Span
Last Post by ~s.o.s~
0

Use the ServletContext's getRealPath() method to grab hold of the OS dependent real path of your web application's root. For e.g. on Windows system, it might look something along the lines of F:\Tomcat6\webapps\MyWebApplication] .

BTW, I am pretty sure that there are better ways of doing the thing you are trying there; just stream the generated bytes to the user by setting the appropriate response headers so that he gets the 'Save As / Open' pop up. Creating files and spawing threads and one of the few things you have to be *very* careful about in a managed environment.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.