Skip to Content
author's profile photo
Former Member

How to access extern files from a servlet

Greetings,

I am using the 90-days-trial Version of SAP Web AS 6.40 and the SAP NetWeaver Developer Studio.

I have created a HTTP Servlet that reveives a XML-file. Now I want to parse and validate this file. The class that I have created to validate this file works fine and also the communication with the servlet does not make any problems.

The problem I have is that I have to use three .xsd files to validate the xml-content. When I use the absolute path to define the location of these three files (on my hard disk), everything works fine. But I did not yet find the right location where to place the xsd files to make them accessible using a relative path.

I already tried to place the files in deifferent locations, and I also created a .jar containing these xsd files, I deployed it and created a reference in the .ear, but this does not work neither.

I would be very grateful if you could give me a hint where to place these files.

Thank you very much in advance.

Bye,

Nadine

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

1 Answer

  • author's profile photo
    Former Member
    Posted on Jul 22, 2004 at 03:52 PM

    Hi Nadine,

    i suggest to copy the XSD files into the package source folder of the class which is using the schemes for validation. A build will copy this resources to the corresponding class folder.

    Assuming the validation class is named "Val", then the following will work, regardless if it's inside a jar or a directory:

    java.io.InputStream oneIn = Val.class.getResourceAsStream("one.xsd");
    /* or alternatively if you need an URL */
    java.net.URL inUrl = Val.class.getResource("one.xsd");

    Hope that helps.

    Regards

    Stefan

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi Nadine,

      assuming that your validation class is located in package "de.nadine.validation", then the source (and class) directory structure has to look like this:

      de

      |-nadine

      ..|-validation

      ....|-Validation.java

      ....|-schema.xsd

      If you then use

      URL schemaURL = de.nadine.validation.Validation.class.getResource("schema.xsd");

      this will work, definitely.

      Hope that helps.

      Regards

      Stefan