Serving files belonging to the web application directory

G

getsanjay.sharma

Hello to all Java programmers out there.

The task I am trying to do here is to serve or access files which
belong to my web application (i.e. present in the WEB-INF/xml
directory) in a servlet. I could have hardcoded the path but what I am
looking for is a solution which employs relative paths.

Attempting to do new File("./xml/Data.xml") doesn't yield the desired
results considering that it starts looking for this folder structure
inside the bin directory of my App server.

Also, would it be a good programming / design practice to format the
data at the server and then serve the client, relieving the client of
knowing what attributes it should be looking for in the response in
case of an Ajax XML response or to send raw data in the form of XML to
the client and let it figure out how the data should be displayed?

Thanks and regards,
S T S
 
M

Mike Schilling

Hello to all Java programmers out there.

The task I am trying to do here is to serve or access files which
belong to my web application (i.e. present in the WEB-INF/xml
directory) in a servlet. I could have hardcoded the path but what I am
looking for is a solution which employs relative paths.

Look at the ServletContext class, in particular ServletContext
..getResource().
 
G

getsanjay.sharma

Look at the ServletContext class, in particular ServletContext
.getResource().

That did the trick, thanks a lot, I really appreciate your timely
help.

So my next question is:
Would it be a good programming / design practice to format the data at
the server and then serve the client, relieving the client of knowing
what attributes it should be looking for in the response in case of an
Ajax XML response or to send raw data in the form of XML to the client
and let it figure out how the data should be displayed?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top