We are hosting a site for a client and they want us to include the header they have on their server into the pages we are hosting. So whenever they change it, it will automatically change on our site.
We are attempting to use the "include" tag in our JSP code. The code we are using is as follows:
<%@ include file="www.CLIENT.com/CLIENT2/MiddlePageFiles/Vendor_header.html" %>
We also tried
<%@ include file="**http://**www.CLIENT.com/CLIENT2/MiddlePageFiles/Vendor_header.html" %>
Unfortunately these aren't working for us. What seems to be happening is that the code is ONLY looking locally for this file and never seems to go "outside" to look for it.
We are able to pull the header into our page when we use an iframe but because of the way the header is constructed/coded the mouse over drop-down menus aren't working as they should when we use the iframe. The drop-down menus are "cascading" underneath the rest of the content on the page and we weren't able to bring them to the "top".
As a temporary work around, were are hosting the HTML on our own servers.
Any ideas?
If you choose to do this in Java, it's nice and easy using the HttpClient from Apache Commons.
public static String fetchSourceHtml( String urlString ) {
try {
HttpClient httpClient = new HttpClient();
GetMethod getMethod = new GetMethod( urlString );
getMethod.setFollowRedirects( true );
int httpStatus = httpClient.executeMethod( getMethod );
if (httpStatus >= 400) {
return "";
}
String sourceHtml = getMethod.getResponseBodyAsString();
return sourceHtml;
}
catch (IOException e) {
return "";
}
}
For a quick and dirty solution, your JSP you can call this method directly. You could, of course, create a taglib tag to call the method if you prefer.
You may want to change the time-out and retry mechanism for HttpClient. By default it will automatically try up to a maximum of 3 times with each attempt timing out after 30s.
However, you probably want to look into caching the strings for a suitable period of time. You really don't want to make 2 blocking external http requests for each page access to your site.