Depending on how much data is dynamically generated you could take a
reverse approach.
Use a static HTML file with all the appropriate references, and
reference the servlet as a javascript 'src'.
Example:
For your dynamic data put a JavaScript reference in your HTML file's
<head> section, such as:
<script language="JavaScript1.1" src="/servlets/myServlet"></script>
This reference, the servlet, should return a javascript function with
data, such as:
function theData()
{
this.text = "There is data here."
}
Note that there is no <script>...</script> tags in the returned data.
When you need to use the data, use a javascript block that creates the
data object, such as:
<script language="JavaScript1.1">
<!--
data = new theData()
document.write(data.text)
// -->
</script>
Now, just wrap some normal HTML around this and you have your dymanic
data without having to overload your servlet with file finding and
relative URLs.
This works because the 'src' attribute of the <script> tag does not care
if the URL is a file or a servlet.
As an added bonus, you now even have the option of creating several HTML
pages that use the same data but present them in a different format, or
have someone else create the HTML files based on the data that you agree
to supply through the servlet.
Another note is that cookies still work with this method, so you can
still track people through a site even though they are hitting static
files. This technique is very usefull for text based counters.
One word of caution. This may not work with 3.0 browsers.
Tim Gallagher
-----Original Message-----
From: Ackerman, Lee [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, March 10, 1999 10:50 AM
To: [EMAIL PROTECTED]
Subject: Accessing Static html files and images
I'm hoping that there is a simple answer to the following:
I need to be able to have my servlet generate a dynamic HTML file that
references static elements such as a javascript file and an image. Is
there a way to use relative paths to specify where to retrieve these
items? Or do I have to write a servlet that handles the request of the
static files? I have the Servlet book by Jason Hunter and he has a
sample servlet that can be used for the retieval of static files - do I
have to use something like this in order to have this mix of dynamic and
static html?
Thanks for you help!
Lee Ackerman
(403)264-0955
________________________________________________________________________
___
To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html