How to include a static or uploaded file in Veloci

2019-04-08 21:16发布

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.

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" 

This fails

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

as Velocity cannot find the file, with this output

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

and this in logs

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]

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.

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?

标签: velocity
2条回答
2楼-- · 2019-04-08 22:19

I have successfully used like this:

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

Maybe is your file path wrong?

查看更多
在下西门庆
3楼-- · 2019-04-08 22:21

I think #include performs the loading of another template file (.vm), not a css file.

查看更多
登录 后发表回答