diff --git a/pom.xml b/pom.xml index 3a40f08..d6cf3e8 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 loophole.mvc lmvc - 1.06.00 + 1.06.01-SNAPSHOT jar lmvc diff --git a/src/main/java/loophole/mvc/base/TemplateServlet.java b/src/main/java/loophole/mvc/base/TemplateServlet.java index 288bd0e..4dd1051 100644 --- a/src/main/java/loophole/mvc/base/TemplateServlet.java +++ b/src/main/java/loophole/mvc/base/TemplateServlet.java @@ -27,42 +27,49 @@ */ package loophole.mvc.base; -import loophole.mvc.config.TemplateConfig; -import org.thymeleaf.TemplateEngine; -import org.thymeleaf.context.WebContext; +import java.io.IOException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import java.io.IOException; + +import org.apache.commons.lang3.StringUtils; +import org.thymeleaf.TemplateEngine; +import org.thymeleaf.context.WebContext; + +import loophole.mvc.config.TemplateConfig; @WebServlet("*" + TemplateServlet.VIEW_EXT) public class TemplateServlet extends HttpServlet { - public static final String VIEW_EXT = ".html"; - private static final long serialVersionUID = 411L; + public static final String VIEW_EXT = ".html"; + private static final long serialVersionUID = 411L; + + public TemplateServlet() { + super(); + } + + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { - public TemplateServlet() { - super(); - } + TemplateEngine engine = TemplateConfig.getTemplateEngine(request.getServletContext()); + WebContext context = new WebContext(request, response, request.getServletContext()); + context.getResponse().setContentType("text/html; charset=UTF-8"); + String uri = request.getRequestURI() + .replaceAll("\\" + TemplateServlet.VIEW_EXT + ".*", TemplateServlet.VIEW_EXT) + .replaceAll("^" + request.getContextPath(), ""); - @Override - protected void doGet(HttpServletRequest request, HttpServletResponse response) - throws IOException { + if (StringUtils.equals("/", uri)) { + uri = "/index.html"; + } - TemplateEngine engine = TemplateConfig.getTemplateEngine(request.getServletContext()); - WebContext context = new WebContext(request, response, request.getServletContext()); - context.getResponse().setContentType("text/html; charset=UTF-8"); - String uri = request.getRequestURI().replaceAll("\\" + TemplateServlet.VIEW_EXT + ".*", TemplateServlet.VIEW_EXT) - .replaceAll("^" + request.getContextPath(), ""); - engine.process(uri, context, response.getWriter()); - } + engine.process(uri, context, response.getWriter()); + } - @Override - protected void doPost(HttpServletRequest request, HttpServletResponse response) - throws IOException { + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { - doGet(request, response); - } + doGet(request, response); + } } \ No newline at end of file