简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM