0
votes

I haven't had much luck finding out why this is returning null for ServletContext objects.

I've tried using relative and absolute file locations, both are returning null. I've tried moving the template to a deeper path, as i've read elsewhere on SO but it still returns a null. Perhaps I'm not quite understanding why it's returning null, is it not finding the file? It's not throwing an exception, so I'm having troubles understanding what is going on here.

ServletContext context = getServletContext();
InputStream is = context.getResourceAsStream("/WEB-INF/" + templateLocation);
1
What is your runtime classpath?Sotirios Delimanolis
I am remotely debugging in Eclipse off of a tomcat server, so looking at the Debug configuration, i don't see an option for classpath like I would if I created a Java applicationCriel

1 Answers

1
votes

It is not finding the file. The documentation of ServletContext specifies that getResourceAsStream returns

the InputStream returned to the servlet, or null if no resource exists at the specified path

Note that not exceptions are thrown if the file doesn't exist. Check that the file is actually present in (tomcat path)/webapp/(context)/WEB-INF/(templateLocation) on the remote server.