Access files in deployed war from within JSP?

J

Java Job

I have a .war file that is deployed across many different types of
J2EE containers. The .war file contains my JSP code, as well as data
files that reside in [myapp]/lib (they can reside in any directory
such as [myapp]/WEB-INF, etc.)

I need to access the contents of the files inside the JSP using
RandomAccessFile... this means I can NOT use any of the
getResourceAsStream methods to access the file contents.

Ideally I would be able to find out from within my JSP where it is
that the web application is installed and access that directory from
within the .JSP. However, I can not find a reliable way to determine
which directory I am running in and also access a file within the
directory.

Any ideas?

Thanks,
Cliff.
 
M

Mike Schilling

Java Job said:
I have a .war file that is deployed across many different types of
J2EE containers. The .war file contains my JSP code, as well as data
files that reside in [myapp]/lib (they can reside in any directory
such as [myapp]/WEB-INF, etc.)

I need to access the contents of the files inside the JSP using
RandomAccessFile... this means I can NOT use any of the
getResourceAsStream methods to access the file contents.

Ideally I would be able to find out from within my JSP where it is
that the web application is installed and access that directory from
within the .JSP. However, I can not find a reliable way to determine
which directory I am running in and also access a file within the
directory.

Any ideas?

Some containers don't expand the .war file, making it impossible to acess
your files as files. In this case, you'd need to access them via
getResourceAsStream(). If not too large, you could read them into memory
and access them directly. Otherwise, you'd need to copy them to a temp file
and access the temp file.

In the case that the war file is expanded, determining where the webapp is
installed is container-specfic at best, and likely version-dependent as
well. You'll need to start with ServletContext.getServerInfo() to get the
container type and go from there.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top