This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes portability issues with file i/o Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "portability issues with file i/o" Watch "portability issues with file i/o" New topic

portability issues with file i/o

Micah Wedemeyer
Ranch Hand

Joined: Jun 11, 2001
Posts: 68
Is there any sort of specifics as to where a servlet's "home" directory is? When my servlet writes a file, it seems almost arbitrary where it goes. On Tomcat it goes into the /bin directory while on JRun 2.3 it goes into the enclosing web server main directory. This is causing problems for me on JRun due to read/write security restrictions.
I suppose it would be possible to give an absolute path, but this would destroy portability across even a single machine, let alone multiple Servlet Engines. Does anyone have any suggestions?
Micah Wedemeyer
Ranch Hand

Joined: Jun 11, 2001
Posts: 68
Never mind. After some concerted searching on the rest of the board I found the getServletContext().getRealPath() stuff.
Thanks to anyone who was going to help
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15950

Hmmm. I think you may have solved quite a few people's problems here. However, this isn't literally the "home" of the servlet - it's the absolute pathname for a given context (virtual path), so it's not for everyone. And they did note it breaks down if the item in question's inside a "WAR".
Still, it's good to know...

Customer surveys are for companies who didn't pay proper attention to begin with.
I agree. Here's the link:
subject: portability issues with file i/o
Similar Threads
JRUN question!
Compiling the servlet
Where in deployment environment to put a class of an applet, a servlet and HTTP(applet-servlet comm)
JRUN4 WAR Deployment
unable to display image files in jsp