HELP REQUIRED.....Error on 'application.getResourceAsStream' in JSP

Discussion in 'Java' started by Attiq ur Rehman, Mar 3, 2005.

  1. Hi All,

    I'm getting error when I use the following code


    String XSL_STYLESHEET="/custom/test.xsl";

    InputStreamReader inXsl =
    new InputStreamReader(application.getResourceAsStream(XSL_STYLESHEET));




    I get the following error:

    Method getResourceAsStream(java.lang.String) not found in interface
    javax.servlet.ServletContext. InputStreamReader inXsl = new
    InputStreamReader(application.getResourceAsStream(XSL_STYLESHEET));

    I have JDK 1.3 installed on windows 2000, and I'm using Apache server
    with Oracle 9i,


    On another machine, I have JDeveloper 9.0 installed and the above
    given code works fine there.

    Any hint how I can solve it.


    Thanks in advance.


    With Regards,
    Attiq ur-Rehman
     
    Attiq ur Rehman, Mar 3, 2005
    #1
    1. Advertisements

  2. Attiq ur Rehman

    Rhino Guest

    What class is the object 'application'?

    It would appear that 'application' belongs to a class that doesn't have a
    getResourceAsStream() method in JDK 1.3. It appears that the JDK you are
    using in JDeveloper *does* have a getResourceAsStream() method so it is
    probably a JDK that is newer than 1.3.

    You'll probably have to upgrade the JDK you are using to the same level as
    the one on the machine running JDeveloper.

    Rhino
     
    Rhino, Mar 3, 2005
    #2
    1. Advertisements

  3. Attiq ur Rehman

    Malte Guest

    I fought this for a long time and came up with this generic solution:

    WEB-INF/xsl has all my xsl files
    WEB-INF/conf has all my configuration files
    WEB-INF/log has all my log files

    JSP has code like this:

    String where_are_my_files =
    this.getServletConfig().getServletContext().getRealPath("/WEB-INF/xsl/"));

    IMHO, this is very clean and portable.

    There are also standard api's to handle extraction of strings from your
    your web.xml file:

    <context-param>
    <param-name>stylesheet-directory</param-name>
    <param-value>/WEB-INF/xsl</param-value>
    <description>Location of xsl stylesheets</description>
    </context-param>
     
    Malte, Mar 3, 2005
    #3

  4. Hi,

    Thanks for reply.

    Even if I use the following code, I get the same type of error. I just
    want to know if there is any special configutration in Apache server
    to run the code.

    I changed the code to the following one:

    String XSL_STYLESHEET="/custom/test.xsl";


    InputStreamReader inXsl = new
    InputStreamReader(this.getServletConfig().getServletContext().getResourceAsStream(XSL_STYLESHEET));


    I get the following error:

    Method getResourceAsStream(java.lang.String) not found in interface
    javax.servlet.ServletContext. InputStreamReader inXsl = new
    InputStreamReader(this.getServletConfig().getServletContext().getResourceAsStream(XSL_STYLESHEET));



    Regards,
    Attiq
     
    Attiq ur Rehman, Mar 4, 2005
    #4
  5. Attiq ur Rehman

    Malte Guest

    FWIW, my finding, and I may be wrong, is that using getResourceAsStream
    is about the slowest possible method of finding anything along the
    CLASSPATH.

    If you use J2EE, you might as well make use of the J2EE way of finding
    stuff.
     
    Malte, Mar 4, 2005
    #5
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.