The ServletContext
is not the same as the context path of your application. The ServletContext
is an object that your web application can use to interface with the servlet container. Hence, what you're doing with your approach is to concatenate that object with a String
, which invokes it's toString()
method, which just prints the implementing class name and it's hashcode. Which obviously does not match your path.
What you instead need to do is to use the ServletContext
to get a URL
to your file. And to do that, you actually use the ServletContext
. You can get the URL
of a file in your web application with the getResource
method of the ServletContext
. Something like this:
builder.parse(context.getResource('/WEB-INF/config/config.xml'));
This requires your parse
method to accept a URL
object. You can also use getResourceAsStream()
, if your builder accepts a parameter of type InputStream
instead.