read from file in jsp

Discussion in 'Java' started by Nikolaj, Jul 4, 2003.

  1. Nikolaj

    Nikolaj Guest

    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
     
    Nikolaj, Jul 4, 2003
    #1
    1. Advertising

  2. Nikolaj

    Chris Smith Guest

    William Brogden wrote:
    >
    > "Nikolaj" <> wrote in message
    > news:...
    > > 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
     
    Chris Smith, Jul 4, 2003
    #2
    1. Advertising

  3. "Nikolaj" <> wrote in message
    news:...
    > 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 =---
     
    William Brogden, Jul 4, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    4,396
  2. Replies:
    8
    Views:
    3,488
    Manish Pandit
    Oct 11, 2006
  3. tiewknvc9
    Replies:
    4
    Views:
    1,763
  4. LB
    Replies:
    0
    Views:
    752
  5. Alex Dowad
    Replies:
    4
    Views:
    272
    Michel Demazure
    May 1, 2010
Loading...

Share This Page