开发者

Java EE Application Directory Best Practice Question

I am relatively new at Java EE and have just gotten familiar with the traditional application directory structure (which includes the BUILD, DIST, NBPROJECT, SRC, and WEB fo开发者_开发知识库lders). I was wondering: if my application requires to use some resources/assets (such as images or pdfs) on the server, in which of the 5 folders listed above should I place those resources? I think I can technically place them anywhere, as long as I reference the files correctly, but not sure what the common best practice is for this.


You would usually include static content e.g. images or PDFs which need to be read by http requests in WebContent e.g. if my-web is your WAR project:

my-web/WebContent/images
my-web/WebContent/scripts
my-web/WebContent/misc

This means you can access using for example:

/my-web/images/bob.jpg
/my-web/scripts/bob.js
/my-web/misc/bob.pdf

Storing the files here allows public access. I will quote this from the Eclipse help pages:

The Web content folder represents the contents of the WAR file that will be deployed to the server. Any files not under the Web content folder are considered development-time resources (for example, .java files, .sql files, and .mif files), and are not deployed when the project is unit tested or published.


You need to think about how the assets get delivered to the client before deciding where to put them. Resources such as ccs and static html pages are retrieved by the client using separate HTTP calls, so they need to be in a place that is accessible. In your case, I'd say they have to be at the level of index.jsp, or in subdirectories at that level. If you put them in WEB-INF, they will be inacessible from the outside world. You could possibly put them in META-INF but it would be an unusual use of that directory.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜