Add file in package functionality.

This commit is contained in:
Christian P. MOMON 2013-07-01 02:01:40 +02:00
parent cc7639aeb9
commit 2c08119da5

View file

@ -123,13 +123,16 @@ public class SimpleServletDispatcher extends HttpServlet
{ {
// path = getServletContext().getRealPath("/") + // path = getServletContext().getRealPath("/") +
// request.getRequestURI(); // request.getRequestURI();
// First, search file in the WebContent root.
path = getServletContext().getRealPath("/") + request.getPathInfo(); path = getServletContext().getRealPath("/") + request.getPathInfo();
logger.info("path1=" + getServletContext().getRealPath("/")); logger.info("path1=" + path);
if (!new File(path).exists()) if (!new File(path).exists())
{ {
path = getServletContext().getRealPath("/") + this.webclassesRootPath + "/" + request.getPathInfo(); // If file is not in WebContent root, search it in packaged
// classes.
path = getServletContext().getRealPath("/") + "WEB-INF/classes/" + this.webclassesRootPath.replaceAll("\\.", "/") + request.getPathInfo();
} }
logger.info("path2=" + getServletContext().getRealPath("/") + this.webclassesRootPath); logger.info("path2=" + path);
returnInlineFile(response, new File(path), getServletContext().getMimeType(path)); returnInlineFile(response, new File(path), getServletContext().getMimeType(path));
logger.info("File returned directly [" + path + "] with mimetype [" + getServletContext().getMimeType(path) + "]."); logger.info("File returned directly [" + path + "] with mimetype [" + getServletContext().getMimeType(path) + "].");