Results 1 to 3 of 3
  1. #1
    khdani is offline Member
    Join Date
    Aug 2008
    Posts
    14
    Rep Power
    0

    Default load xml file in servlet help please

    Hello,
    i use myEclipse for creating a servlet.
    i'm trying to load xml file in servlet..but i don't understand where
    i should put the file in real path and/or how to load the file.
    thank you

  2. #2
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    6

    Default

    the best place to put things like data (xml files) is inside the WEB-INF folder, if it is desireable to have the XML file live within the web application. and then the method ServletContext#getResourceAsStream() is useful for figuring out the deployment-dependent path relative to the webapplication, and fetching you an open InputStream, which can then be used with the XML parsers.

    If the XML file must exist externally to the web application, a good idea is to define an context parameter in the web.xml, or maybe use a JNDI environmnt variable name, which can be overridden with the container-specific deployment descriptor. for example, tomcat's context.xml could provider the resource binding for the physical external to the web application path, and the code inside your webapp would fetch a handle to the jndi variable name in a deployment-independent manner.

  3. #3
    khdani is offline Member
    Join Date
    Aug 2008
    Posts
    14
    Rep Power
    0

    Default

    Thank You for your reply,
    I've already finished developing this servlet,
    if I remember correctly, the way you described, that's the way I used to load the xml file, which was part of the web application.

    Thank You

Similar Threads

  1. Load file to data structure
    By TinoJF in forum New To Java
    Replies: 4
    Last Post: 03-31-2009, 04:16 PM
  2. Replies: 0
    Last Post: 08-30-2008, 12:52 PM
  3. Not able to load a properties file
    By Happy9959 in forum New To Java
    Replies: 12
    Last Post: 07-29-2008, 08:15 AM
  4. how to load a servlet on index.jsp page...
    By sujithc34 in forum Java Servlet
    Replies: 1
    Last Post: 01-19-2008, 01:28 AM
  5. how to load a file in remote machine
    By christina in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 10:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •