1

例外が発生しました: org.apache.velocity.exception.ResourceNotFoundException: リソース 'ResourceLoader1.vm' が見つかりません

/WEB-INF/templates に ResourceLoader1.vm があります。これで行き詰まりました。助けてください。

            Properties props = new Properties();  
            props.put("file.resource.loader.path", "/WEB-INF/templates");
            Velocity.init(props);
            VelocityContext context = new VelocityContext();
            context.put("greetings", "Many Happy returns");
            context.put("name", "Joseph");
            Writer writer = new StringWriter();
            Template template = Velocity.getTemplate("ResourceLoader1.vm");
            template.merge(context, writer);
4

2 に答える 2

4

.vm テンプレートは、CLASSPATH に対して相対的に配置する必要があります。より良い選択は、 /templates ディレクトリを WEB-INF/classes の下に置き、小道具を失い、次のように取得することです。

Template template = Velocity.getTemplate("templates/ResourceLoader1.vm");
于 2012-11-06T10:16:27.430 に答える
3

Web アプリケーションで Velocity を使用しているようです。このためには、この種の使用のために特別に設計されたVelocityViewServletを使用することをお勧めします。

構成で使用されるFileResourceLoaderには、Web サーバーとコンテキストなどに関する知識がないため、構成した方法では、アプリケーション サーバーが実行されているファイル システムのルートにWEB-INFあるフォルダーを探します。

于 2012-11-06T10:31:55.980 に答える