Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Load xml file

Posted on 2006-06-12
5
Medium Priority
?
217 Views
Last Modified: 2010-04-01
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.
0
Comment
Question by:wilflife
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 35

Assisted Solution

by:TimYates
TimYates earned 1000 total points
ID: 16883736
File theFile = new File( getServletContext().getRealPath( "/xmlfile.xml" ) ) ;

Tim
0
 
LVL 8

Accepted Solution

by:
colr__ earned 1000 total points
ID: 16883750
TimYates post should work, but one thing to consider - the reason you are having to put the full path in is because the relative URL is from the web server executable. For example, even though your site may be in the folder 'mySites', as far as java is concerned, your running the program from the application servers root directory, and so this location is your relative path.

Doesnt help you, but this is why your getting this result.

colr__
0
 

Author Comment

by:wilflife
ID: 16883987
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.
0
 
LVL 35

Expert Comment

by:TimYates
ID: 16883994
>> 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
0
 
LVL 8

Expert Comment

by:colr__
ID: 16883996
The only problem with that method is that it isnt portable. In most cases this wont be a problem, but good to know.

colr__
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As much as Microsoft wants to kill off PST file support, just as they tried to do with public folders, there are still times when it is useful or downright necessary to export Exchange mailboxes to PST files. Thankfully, it is still possible to e…
With so many activities to perform, Exchange administrators are always busy in organizations. If everything, including Exchange Servers, Outlook clients, and Office 365 accounts work without any issues, they can sit and relax. But unfortunately, it…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question