Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

read xml file from jsp/servlet

843835Apr 24 2003 — edited Apr 30 2003
Hi all,

I am a new comer to jsp and really appreciate if someone can help me on this:

I will like to use a xml file to control access to my web app instead of using a database. Let say user.xml that will contains user name and password. Questions:

1. where should I put this file? Under WEB-INF?

2. In my jsp or servlet, how do i read the xml file, i mean how to i refer to the file (depend on question 1 as where the file should be placed)?

Thank you very much.


Sim

Comments

843835
Hi jlsim,
you can place the xml file where you want, but remember that placing it under /WEB-INF is the most security way.
I had a similar problem and I placed the xml file under /WEB-INF directory.
To refer to it I did something like this:

String realPath=getServletContext().getRealPath("WEB-INF/xml/workspaces.xml");//obtain the real path

File f=new File(realPath);//obtain an instance of your file usable
//to create an InputStream
843835
btw, are u using tomcat?? If Tomcat, put your xml file in Tomcat\webapps\ROOT\your folder\user.xml or Tomcat\webapps\ROOT\user.xml..

Hope it helps u..
843835
Do u mean that in tomcat i can't put my xml file in WEB-INF? Coz as far as i now it is safest there as it won't get published out.
843835
I not so sure abt that but so far when i did it, i put my xml in my foder, not in WEB-INF
843835
Of course, you cant put your xml files in /WEB-INF!!!
Try the implementation I suggested and give me a feed-back!
843835
Don't you mean you can put your xml file in the WEB-INF? Experience and your example both suggest so.
843835
Ops,
yes I mean that you can .
1 - 7
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on May 28 2003
Added on Apr 24 2003
7 comments
133 views