从 Java Web 服务器链接外部文件
我有一个 java servlet,它根据请求处理数据并生成图像。可能有数百万张图像,一旦生成,就不需要重新渲染,因此我想缓存它们并避免渲染步骤,因为它非常乏味。
我的缓存工作正常,但问题是我需要这些渲染的图像在我的 Web 应用程序的部署之间保留,即我无法将它们写入文档库,否则它们会在重新部署时被破坏。
我一直在做的是使用上下文的“allowLinking”属性,因为我的Web应用程序被部署为war文件(上下文位于META-INF/context.xml中)。这有点乏味,因为我需要在取消部署应用程序之前打破符号链接,否则链接中的图像会被破坏,但它似乎有效。
但这仅适用于 Tomcat,并且在使用 JBoss (5.1) 进行测试时,它似乎不支持符号链接,并且不允许链接到文档库之外的任何内容。我认为必须有一种更实用的方法来实现这一点,并且适用于所有 Java Web 服务器。我缺少什么?
I have a java servlet that upon a request crunches on data and produces an image. There can potentially be millions of images and once produced they don't need to be re-rendered so I'd like to cache them and avoid the render step as it is quite tedious.
I have the cacheing working fine but the problem is I need these rendered images to persist between deployments of my web application, i.e., I can't write them into the docbase or else they get destroyed upon redeployment.
What I've been doing is using the 'allowLinking' attribute of the Context as my web application is deployed as a war file (context is in META-INF/context.xml). This is somewhat tedious because I need to break the symbolic link before my application is undeployed or else the images in the link are destroyed, but it seems to work.
But this only works for Tomcat and when testing with JBoss (5.1) it doesn't seem to honor the symbolic link and doesn't allow linking to anything outside of the docbase. I'm thinking there has to be a more practical way to accomplish this that works for all Java Web Servers. What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您只需配置一个 servlet,即可从外部目录提供图像。该 servlet 只需从请求中提取图像文件名或 ID,从外部目录读取文件并将字节写入 servlet 响应的输出流(在响应上设置适当的内容类型)。
或者,您可以添加一个 Apache httpd 服务器前端,该前端将提供来自某个外部目录的静态图像,并委托给您的 servlet 容器来获取其他 URL。
You could just configure a servlet that would serve the images from an external directory. This servlet would just have to extract the image file name or ID from the request, read the file from an external directory and write the bytes to the servlet response's output stream (with the appropriate content type set on the response).
Or you could add an Apache httpd server front-end which would serve the static images from some external directory, and delegate to your servlet container for the other URLs.