如何为GlassFish Web应用程序提供对外部资源(文件)的访问? [英] How to provide access to an external resource (file) for a GlassFish web application?

查看:79
本文介绍了如何为GlassFish Web应用程序提供对外部资源(文件)的访问?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有点像 GlassFish 初学者,所以请原谅我关于这个主题的想法。

基本上我们正在为一个游戏网站提供服务,并且通过我们的网络应用程序让客户端可以下载,我们将它复制到domain1中的一个目录中。问题是,当重新部署Web应用程序时,客户端可下载程序丢失,我们必须再次复制它。



我希望能够存储客户端可以在某个外部位置下载,并且可以通过GlassFish提供对其的访问。



我可以将链接硬编码到Web应用程序中,但这样我们就失去了可移植性,所以这就是原因因为GlassFish可以处理它。



我也可以将客户端下载到我们的数据库中,但这似乎是对数据库使用不当,也可能导致数据库性能不佳。 / p>

我发现的第三个选项是添加一个自定义资源映射,从某个名称到文件位置,然后在我的一个bean中提供一个方法来检索文件位置。这似乎有很多工作只是为了拥有一个外部资源,我觉得必须有一个更简单的方法。



那么我该怎么做?

解决方案

使用GlassFish,您可以定义替代文档根目录来提供战争以外的文件。从文档:


替代文档根



替代文档根(docroot)
基于
,Web应用程序可以为自己的docroot之外的
服务
的某些资源的请求提供服务,无论这些请求是否匹配网站的URI模式中的一个(或
多)
应用程序的备用docroots。

要为
web应用程序或虚拟服务器指定一个备用docroot,
使用 alternatedocroot_n 属性,
其中 n 是一个正整数,
允许指定多个。
此属性可以是
sun-web中
sun-web-app 元素的子元素.xml
文件或虚拟服务器
属性。有关
这些元素的更多信息,请参阅 sun-web-app in
Oracle GlassFish Server 3.0.1
应用程序部署指南

所以你可以像这样配置:

 < property name =alternatedocroot_1value =from = / ext / * dir = / path / to / ext/> 

请参阅文档以获取完整详情。


I am a bit of a GlassFish beginner, so please forgive my ingnorance on the subject.

Basically we are serving a game website, and to make the client downloadable by our web app we copy it into a directory within domain1. The problem with this is that when redeploying the web app the client downloadable is lost and we have to copy it across again.

I'd like to be able to store the client downloadable in some external location and have GlassFish provide access to it.

I could just hardcode the link into the web app, but then we would lose portability so that's the reason for having GlassFish handle it.

I could also put the client downloadable into our database but that seems like poor use of a database and could also result in poor database performance.

The third option I have found is to add a custom resource mapping from some name to the file location, and then provide a method in one of my beans to retrieve the file location. This seems like a lot of work just to have an external resource, I feel like there must be an easier way.

So what should I do?

解决方案

With GlassFish you can define an alternate document root to serve files from outside the war. From the documentation:

Alternate Document Roots

An alternate document root (docroot) allows a web application to serve requests for certain resources from outside its own docroot, based on whether those requests match one (or more) of the URI patterns of the web application's alternate docroots.

To specify an alternate docroot for a web application or a virtual server, use the alternatedocroot_n property, where n is a positive integer that allows specification of more than one. This property can be a subelement of a sun-web-app element in the sun-web.xml file or a virtual server property. For more information about these elements, see sun-web-app in Oracle GlassFish Server 3.0.1 Application Deployment Guide.

So you could configure something like this:

<property name="alternatedocroot_1" value="from=/ext/* dir=/path/to/ext"/>

Refer to the documentation for full details.

这篇关于如何为GlassFish Web应用程序提供对外部资源(文件)的访问?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆