如何通过#include 在 Velocity 宏中包含静态或上传的文件 [英] How to include a static or uploaded file in Velocity macro via #include

查看:35
本文介绍了如何通过#include 在 Velocity 宏中包含静态或上传的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过在初始请求下载的 HTML 中内嵌一些 CSS 来优化一些移动网页(或更准确的服务器请求数量).

I am trying to optimize some mobile web pages (or number of server requests more accurately) by in-lining some CSS in the HTML downloaded with initial request.

这些页面来自我们基于 Vosao 的 CMS,并使用 Apache Velocity 宏.

These pages are delivered from our Vosao-based CMS, and use Apache Velocity macros.

这很好,正如预期的那样.

This works fine, as expected.

<link rel="stylesheet" type="text/css" media="screen" href="/file/downloads/contact.css" 

失败

<style>
#include( "/file/downloads/contact.css" )
</style>

因为 Velocity 找不到文件,所以输出了

as Velocity cannot find the file, with this output

org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource '/file/downloads/contact.css'

这在日志中

org.apache.velocity.runtime.log.CommonsLogLogChute log: ResourceManager : unable to find resource '/file/Downloads/contact.css' in any resource loader.
E 2012-06-20 13:59:19.688
org.apache.velocity.runtime.log.CommonsLogLogChute log: #include(): cannot find resource '/file/Downloads/contact.css', called at vm[line 7, column 3]

我已经阅读了速度文档(关于资源 ROOT 属性),甚至在源代码上花了一些时间.我在加载时使用了这些属性......但没有运气.

I have read the velocity documentation (about resource ROOT property) and even spent some time on the source code. I've played with the properties for that at load time....and no luck.

如何让 Velocity 在我的/war 目录中包含静态文件,或者从路径中包含它?

How can I get Velocity to do an include of either a static file in my /war dir, or getter it to include from a path?

推荐答案

我已经成功使用过这样的:

I have successfully used like this:

<style type="text/css">
  #include("my/path/to/file/file.css")
</style>

可能是你的文件路径不对?

Maybe is your file path wrong?

这篇关于如何通过#include 在 Velocity 宏中包含静态或上传的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆