当前位置: 动力学知识库 > 问答 > 编程问答 >

web applications - How to host and refer to static content from within your ear file

问题描述:

We have several j2ee applications (e.g. A.ear, B.ear, C.war) running in a single jboss instance, we have a requirement to share a set of static files across these applications. So I should be in a position to access these files as http://myhost/folderA/fileA.htm or http://myhost/folderB/file.js from within my ear or war files.

How should I tell the jboss appserver (5.1.0) to look for these files, how should I deploy this static content in my server/default/deploy directory or the docs folder

网友答案:

If you're using jboss with the Jetty server, you can re-use the org.mortbay.jetty.servlet.DefaultServlet. I am sure tomcat has something similar or you can just add the jetty one (because it's a servlet, it will run on any servlet container). Even though it's relatively easy to write it yourself, it's not because there are a bunch of things a quality implementation needs.

Take a look at the documentation of the DefaultServlet on how to configure it, it has many features.

网友答案:

You should be able to place the static files in one location and have each of your contexts (A, B, C,...) have a servlet that serves these static files.

If you can configure it to look in the right folder, you may be able to reuse an existing servlet like DefaultServlet. Or you may code your own servlet to serve static content: I once wrote one here.

分享给朋友:
您可能感兴趣的文章:
随机阅读: