I have the following structure in a Java Web Application:
TheProject
-- [WebContent]
-- -- [WEB-INF]
-- -- index.jsp
-- -- [IMAGES]
-- -- -- image.jpg
-- [Source Packages]
----ImageHandlerServlet.java
In ImageHandlerServlet.java, I am using the following code
String path = getServletContext().getRealPath("/Images");
Which gives following path. D:\BH\workspace.metadata.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\proj\Images
URL path2 =getServletContext().getResource("/image.jpg");
which returns null.
InputStream stream = getServletContext().getResourceAsStream("/image.jpg");
which returns null;
I want to read the file from WebContent/IMAGES/ instead of WEB-INF. Using real path it can be achieved. What should I do? I consulted following related posts.