我正在尝试在 tomcat7 上使用带有 servlet 3.0 的 Rythm 模板引擎。
我想将模板从 WebContent
目录渲染到 Rythm
引擎。但它没有检测到模板。
在 servlet init()
方法中,我将 Rthym 引擎初始化为
public void init(ServletConfig config) throws ServletException {
Map <String, Object> context = new HashMap <String, Object> ();
//String filePath = new File("").getAbsolutePath();
//filePath.concat("WebContent");
context.put("home.template", "WebContent");
Rythm.init(context);
}
然后我尝试在 doGet
方法中使用 Rythm.render
渲染我的 NewFile.html
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Map <String, Object> args = new HashMap <String, Object> ();
args.put("a", "World");
PrintWriter out = response.getWriter();
out.println(Rythm.render("NewFile.html", args));
}
但它在浏览器中仅显示“NewFile.html”(不是 NewFile.html 的内容,而仅显示字符串“NewFile.html”
最佳答案
我对 Rythm 也有类似的问题,就我而言,它有助于在文件名前面写入目录:
Rythm.render("templates/" + templateFileName, parameters);
设置 home.template
变量对我来说也不起作用。
关于java - 无法将 Rythm 模板引擎与 servlet 3.0 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26494075/