Is it possible to find out deployment path from JSF application?
One more question (if the answer for the former question is true): is it legitimate to store some uploaded files there?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Not directly, you’d need to grab the
ServletContextfrom theExternalContextas follows:It in turn offers the well-known and dubious
getRealPath()method.If you’re already on JSF 2.0, you could use
ExternalContext#getRealPath()instead.You can do so. You only need to take into account that they all get lost whenever you redeploy the application, for the very simple reason that those files are not contained in the original WAR.
If you’d like to have a bit more permanent storage, consider storing it in a fixed path outside the webapplication, e.g.
/var/webapp/uploador so. An alternative is storing them in a database, this would increase the portability, but remember to store some metadata (name, content type, last modified timestamp, etc) along the file content as well so that you have something to index/search/cache on.