gpt4 book ai didi

java - Servlet 的工作/包含直接

转载 作者:行者123 更新时间:2023-11-28 22:46:06 24 4
gpt4 key购买 nike

我目前正在开始学习使用 java 来创建动态网站。我已经开始使用 servlet 和模板引擎“velocity”。

我的环境:

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

最佳答案

尽管 WEB-INF/ 位于类路径中,但您无法在不重新配置 Velocity 的情况下加载模板。 Velocity 默认使用基于文件的方法。您需要告诉 Velocity 查看 Web 应用程序的类路径,然后它使用 ServletContext 加载打包在 Web 应用程序存档中的资源。

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

关于java - Servlet 的工作/包含直接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2975575/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com