read from file in jsp

N

Nikolaj

I'm develloping a site based on jsp.
In my javacode I want to read from a file located in the document root
of the web application. How do I do this when I dont know the name of
the host.

Should I consider locating the file somewhere else. It should actually
only be accessible from the code of the application.

Thanks for your help.

Nikolaj
 
C

Chris Smith

William said:
The servlet API provides for this in the ServletContext class. Example:

InputStream in = config.getServletContext().getResourceAsStream(
"WEB-INF/surveys/survey.properties");

Well, the easier way to access the ServletContext is:

InputStream in = application.getResourceAsStream(...);

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
W

William Brogden

Nikolaj said:
I'm develloping a site based on jsp.
In my javacode I want to read from a file located in the document root
of the web application. How do I do this when I dont know the name of
the host.

Should I consider locating the file somewhere else. It should actually
only be accessible from the code of the application.

The servlet API provides for this in the ServletContext class. Example:

InputStream in = config.getServletContext().getResourceAsStream(
"WEB-INF/surveys/survey.properties");

WBB
 

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

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,188
Latest member
Crypto TaxSoftware

Latest Threads

Top