Criel
Criel

Reputation: 815

ServletContext.getResourceAsStream returning null

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);

Upvotes: 0

Views: 1364

Answers (1)

Javier
Javier

Reputation: 12398

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.

Upvotes: 1

Related Questions