Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > read from file in jsp

Reply
Thread Tools

read from file in jsp

 
 
Nikolaj
Guest
Posts: n/a
 
      07-04-2003
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
 
Reply With Quote
 
 
 
 
Chris Smith
Guest
Posts: n/a
 
      07-04-2003
William Brogden wrote:
>
> "Nikolaj" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) om...
> > 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");


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
 
Reply With Quote
 
 
 
 
William Brogden
Guest
Posts: n/a
 
      07-04-2003

"Nikolaj" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> 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




----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
File.read(fname) vs. File.read(fname,File.size(fname)) Alex Dowad Ruby 4 05-01-2010 08:20 AM
<jsp:useBean File Read Write, File Locations and GoDaddy.com LB Java 0 05-27-2008 01:44 AM
Tomcat not updating index.jsp to my jsp file! tiewknvc9 Java 4 05-12-2007 12:03 AM
Declaring a variable in one JSP file and accessing it in another JSP file anubhakhurana@gmail.com Java 8 10-11-2006 01:15 AM
[JSP] difference between jsp:forward and jsp:include alexjaquet@gmail.com Java 0 06-02-2006 01:21 PM



Advertisments