4

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()+"\""); 
4

1 回答 1

0

代替

ServletContext servletContext = request.raw().getSession().getServletContext();

做这个:

ServletContext context = request.getSession().getServletContext();
于 2014-01-18T22:30:23.353 回答