Re: Accessing files from within an application server
Qu0ll wrote:
I have some files that reside on an application server (GlassFish) and I
would like to read them from within a servlet. How can I reference them?
Is it a matter of accessing the URL of the files? If so, how can it be done
in such a way that it won't matter which port the server is running on?
It's not clear exactly what you are trying to achieve. Do you want to be able to
access the file at a remote client, using the servlet as a "proxy"? Or do you
mean that you want to access a local file within the servlet?
If you want the servlet to serve a local file to a remote client then the URI
the client needs is the URI of your servlet followed by a parameter which would
identify the file in question. The servlet would then respond with the correct
HTML to identify the file MIME type, followed by the file contents.
If you mean that you want to access a local file within the servlet then all you
do is use java.io.File, or any other Java method of accessing local files.
For example, perhaps something like:
file://localhost:8080/filename
No, that won't achieve anything. The file:// URI doesn't take any notice of
host:port. It only accesses the local filesystem so a host and port are
meaningless.
but what happens if the server is deployed on port 80?
From a servlet's POV it doesn't matter. From a client's POV it has to know what
port the server is listening on if it wants to contact it.
Perhaps it's done using the servlet context?
An example would be nice!
--
Nigel Wade, System Administrator, Space Plasma Physics Group,
University of Leicester, Leicester, LE1 7RH, UK
E-mail : nmw@ion.le.ac.uk
Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555