| Java FAQ | ||
| JSP FAQ | ||
| Servlet FAQ | ||
XyzWs Servlet FAQ:
How to use ServletContext.getResourceAsStream()?
Printer-friendly version |
Mail this to a friend
|
Advertisement
|
How to use ServletContext.getResourceAsStream(java.lang.String path)?From API document, this method is different from
ServletContext context = getServletContext();
InputStream is = context.getResourceAsStream("/yourfilename.cnf");
The ServletContext.getResourceAsStream() method the file can be located anywhere in your web application. It is recommended to keep it under the /WEB-INF directory if you don't want browers being able to access it. Your web application should use the ServletContext.getResourceAsStream() API when accessing web application resources.
The path must begin with a "/" and is interpreted as relative to the current context root. This method returns null if no resource exists at the specified path. For example, using a path that doesn't start with a slash, You will get a
ServletContext.getResourceAsStream("WEB-INF/resources/yourfilename.cnf").
|