Glassfish 3-从静态服务器加载图像 [英] Glassfish 3 - Loading images from a static server

查看:32
本文介绍了Glassfish 3-从静态服务器加载图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Web应用程序外部的服务器加载图像(和其他静态内容),该服务器已部署到 Glassfish v3 .我在 web.xml 中具有以下配置,但它不适用于Glassfish(但适用于Tomcat):

I'm trying to load images (and other static content) from a server outside of my web application which is deployed to Glassfish v3. I have the following configs in the web.xml but it does not work on Glassfish (but it works on Tomcat):

<servlet>
    <servlet-name>ExternalImagesServlet</servlet-name>
    <servlet-class>com.example.servlet.HttpProxyServlet</servlet-class>
    <init-param>
        <param-name>RemoteURI</param-name>
        <param-value>http://ip.of.second.server/website-files</param-value>
    </init-param>   
    <init-param>
        <param-name>AllowedContentTypes</param-name>
        <param-value>image/gif,image/jpeg,image/png</param-value>
    </init-param>
</servlet>
<servlet-mapping>
    <servlet-name>ExternalImagesServlet</servlet-name>
    <url-pattern>/images/*</url-pattern>
</servlet-mapping>

其中第二服务器的IP地址是服务器的实际IP地址.我有一个名为 website-files.xml 的文件,定义如下:

Where ip.of.second.server is an actual IP address of the server. I have the file called website-files.xml defined as follow:

<?xml version="1.0" encoding="UTF-8"?>
<Context docBase="d:/internet/website/images" />

然后将website-files.xml保存到 glassfish \ domains \ domain1 \ config 目录中.但是Glassfish不会选择此配置文件.

And website-files.xml is saved to glassfish\domains\domain1\config directory. But Glassfish does not pick up this config file.

我看过Oracle Glassfish配置文档,但没有提及如何引用来自其他服务器的图像.

I have looked at Oracle Glassfish configuration doco but there's no mention on how you can reference images from a different server.

请帮助.

推荐答案

我是根据经过两天搜索后在Google上发现的与Glassfish版本2相关的旧线程解决的.

I have solved it based on an old thread relating to Glassfish version 2 that I found on Google after two days of search.

如果有人对解决方案感兴趣,这里是:

In case anyone is interested in the solution, here it is:

1)直接在 Webcontent \ WEB-INF 目录下创建一个名为 sun-web.xml 的文件,并将以下配置添加到该文件:

1) Create a file called sun-web.xml directly under Webcontent\WEB-INF directory and add the following configuration to this file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sun-web-app PUBLIC "-//Sun Microsystems, Inc.//DTD GlassFish Application Server 3.0 Servlet 3.0//EN" "http://www.sun.com/software/appserver/dtds/sun-web-app_3_0-0.dtd">
<sun-web-app>
   <property name="alternatedocroot_1" value="from=/images/* dir=d:/internet/website" />
   <property name="alternatedocroot_2" value="from=/files/* dir=d:/internet/website" />
</sun-web-app>

2)从 web.xml 文件中删除 servlet servlet-mapping 配置(就像我上面所做的一样). 注意:如果您使用 Tomcat ,上述方法将起作用.

2) Remove the servlet and servlet-mapping configurations from web.xml file (like I did above). Note: The above would work if you were to use Tomcat.

3)从 glassfish \ domains \ domain1 \ config 目录中删除 website-files.xml ,因为Glassfish不需要此文件:注意: Tomcat 需要此文件.

3) Delete the website-files.xml from glassfish\domains\domain1\config directory as this file is not needed by Glassfish: Note: This file is needed by Tomcat.

这篇关于Glassfish 3-从静态服务器加载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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