2010-06-04 48 views
0

我目前开始学习使用java创建动态网站。 我已经开始使用servlet和模板引擎“速度”。工作/包括直接的Servlet

我Environement:

WebContent/ 
    WEB-INF/ 
     gallery/ 
     template.file 

我的问题:我想用 “template.file” 作为模板。我必须输入什么文件名/路径才能从servlet访问我的模板。

对不起,我的英语不好:/目前德国很热。

最好的问候, 安德烈

编辑:一些代码...

/* Create and setup the Template system */ 
template = new VelocityEngine(); 
template.init(); 
template.getTemplate("template.file"); <--- Waht directory to use 
+0

请向我们展示您需要路径的servlet代码。 – 2010-06-04 15:57:31

回答

2

虽然WEB-INF/是在类路径中,你不能没有重新配置速度加载模板。 Velocity默认使用基于文件的方法。您需要告诉Velocity查看Web应用程序的类路径,然后使用ServletContext加载打包在Web应用程序归档文件中的资源。

请参阅Velocity documentation about loading resources in web applications了解如何配置Velocity以从Web应用程序中加载模板的详细说明。

+0

非常感谢你:) – Bigbohne 2010-06-04 16:13:20