开发者

How to get deployment directory path in JSF application?

开发者 https://www.devze.com 2023-01-10 16:21 出处:网络
Is it possible to find out deployment path from JSF appl开发者_如何转开发ication? One more question (if the answer for the former question is true): is it legitimate to store some uploaded files ther

Is it possible to find out deployment path from JSF appl开发者_如何转开发ication?

One more question (if the answer for the former question is true): is it legitimate to store some uploaded files there?


Is it possible to find out deployment path from JSF application?

Not directly, you'd need to grab the ServletContext from the ExternalContext as follows:

ServletContext servletContext = (ServletContext) externalContext.getContext();

It in turn offers the well-known and dubious getRealPath() method.

String webContentRoot = servletContext.getRealPath("/");

If you're already on JSF 2.0, you could use ExternalContext#getRealPath() instead.


One more question (if the answer for the former question is true): is it legitimate to store some uploaded files there?

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/upload or 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号