From 2c08119da5bd74d3454e0965ac2e3fbaf7a54751 Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Mon, 1 Jul 2013 02:01:40 +0200 Subject: [PATCH] Add file in package functionality. --- src/fr/devinsy/kiss4web/SimpleServletDispatcher.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/fr/devinsy/kiss4web/SimpleServletDispatcher.java b/src/fr/devinsy/kiss4web/SimpleServletDispatcher.java index 57ac7f3..0369beb 100755 --- a/src/fr/devinsy/kiss4web/SimpleServletDispatcher.java +++ b/src/fr/devinsy/kiss4web/SimpleServletDispatcher.java @@ -123,13 +123,16 @@ public class SimpleServletDispatcher extends HttpServlet { // path = getServletContext().getRealPath("/") + // request.getRequestURI(); + // First, search file in the WebContent root. path = getServletContext().getRealPath("/") + request.getPathInfo(); - logger.info("path1=" + getServletContext().getRealPath("/")); + logger.info("path1=" + path); 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)); logger.info("File returned directly [" + path + "] with mimetype [" + getServletContext().getMimeType(path) + "].");