[opencms-dev] Include banner in pages (content outside VFS)
Joe Desbonnet
jdesbonnet at gmail.com
Tue Sep 20 14:34:05 CEST 2005
If it's for advertising banners, usually that works by referencing
JavaScript from the adverting system which will insert the advertising
HTML using the browser's Javascript engine. Ie all you need to do is
include a small fragment of JavaScript. Something like this:
<script src="http://ads.adsystem.com/pagead/show_ads.js"
type="text/javascript"> </script>
However I suspect this is not what you need. If you want to grab the
content of a URL and include it in your page, you can do so by
creating a JSP file and using the following code fragment:
-----8<----------8<----------8<----------8<----------8<----------8<-----
<%@page buffer="none" session="false"
import="org.apache.commons.httpclient.*"
import="org.apache.commons.httpclient.methods.*"
%><%!
private String httpGet (String uri) throws Exception {
HttpClient client = new HttpClient();
GetMethod get = new GetMethod(uri);
int status = client.executeMethod(new GetMethod(uri));
return get.getResponseBodyAsString();
}
%>
Here is content from another URL:
<%=httpGet("http://www.myURL.com/blah/blah/blah.html") %>
-----8<----------8<----------8<----------8<----------8<-----
For this you need the HttpClient library from Apache Jakarta Commons.
I cannot remember if this is included in OpenCms or if I put it there.
Look for a file like
commons-httpclient-2.0.2.jar in your WEB-INF/lib directory. As far as
I can remember it's bundled with OpenCms.
Another caveat: this will generate a HTTP GET operation in the
background each time a page is loaded. You will notice it, but the
delay is usually acceptable. Ideally a caching mechanism should be
added.
Another option is to create a scheduled job outside of OpenCms that
grabs the content of your URL periodically and saves it in a fixed
location on the disk. You can then use a small fragment of JSP to
include the content of that file (see doc on java.io.* classes).
Joe.
On 9/20/05, Manuel Wallnoefer <mfw at msk-informatik.at> wrote:
>
>
>
> Hi all,
>
>
>
> i want to include the content of a banner in my pages.
>
>
>
> The banner is outside and I must call the banner with a external URL (
> outside the VFS)
>
>
>
> Now my question is, how do I include content from a page outside the VFS.
>
>
>
> Thx for help
>
>
>
> ~manuel
>
>
> _______________________________________________
> This mail is send to you from the opencms-dev mailing list
> To change your list options, or to unsubscribe from the list, please visit
> http://mail.opencms.org/mailman/listinfo/opencms-dev
>
>
More information about the opencms-dev
mailing list