Link to home
Start Free TrialLog in
Avatar of wilflife
wilflife

asked on

Load xml file

Hi,

I have a jsp file called behind the scenes by a client html file.

The jsp page has to load an xml file which is in the same directory as the jsp page.

The only way i can get it to load is when i put the full windows path.

I use

 File thefile = new File("Thexml.xml"); //does not work

 File thefile = new File(http://correctpathtofilewhichworksinbrowser); //does not work.

File thefile = new File("../directoryabove/xmlfile.xml"); //does not work.


The only way that works is

File thefile = new File( "c:\\pathtofile");

Thanks.
SOLUTION
Avatar of TimYates
TimYates
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of wilflife
wilflife

ASKER

I had to use colr technique, so made sure i could map to the correct directory once i knew where i was.
I couldn't get the

new File( getServletContext().getRealPath( "/xmlfile.xml" ) ) ;

to work even when importing javax.* at the start of my jsp.

Thanks.
>> I couldn't get the <snip> to work even when importing javax.* at the start of my jsp.

You shouldn't have needed to import anything...

especially not javax.* which doesn't import any classes (there is nothing inside javax.*)

Tim
The only problem with that method is that it isnt portable. In most cases this wont be a problem, but good to know.

colr__