Skip to main content

Dynamic alternatedocroot for different operating systems

Please note these forums are being decommissioned and use the new and improved forums at
No replies
Joined: 2012-06-21


I got a huge problem and didn't find a solution till now.

The user should be able to upload pictures to the webserver which should get stored outside the application- or domain directory, because if you redeploy the application the pictures will be deleted. Filename references are stored in a database. I thought of defining a data storage path as JNDI-resource which works fine. But the pictures have to be shown in a Servlet with an "img"-Tag and therefor I have to define a alternatedocroot cause servlets only knows the relative path from the execution directory. And here comes my problem: I can only define hard coded directories as alternatedocroot. But a "/var/uploaded" on Linux is not available on Windows and a "C:\Users\schrotti12\AppData\Roaming\Glassfish\uploaded" is not available for the user "user1". If I could get a reference to a user.home-directory in the web.xml I could define the store-path there but I didn't find any variables available in web.xml.

Any suggestions cause I already switched to Base64-Encoding to transfer files to the webserver which can't be the soulition!