I am trying to get servlet context in Freemarker \ Spark and my getServletContext()
is returning me null
.
ServletContext servletContext = request.raw().getSession().getServletContext();
File titleImage = (File)post.get("titleimage");
resp.setHeader("Content-Type", servletContext.getMimeType(titleImage.getName()));
resp.setHeader("Content-Length", String.valueOf(titleImage.length()));
resp.setHeader("Content-Disposition", "inline; filename=\""+titleImage.getName()+"\"");