用图像封装自定义jsp标签
我正在为客户做一些工作,他们有一个在各种项目中使用的通用 Web 标签 jar 文件项目。他们要求我制作一个页眉和页脚标签,他们可以在使用类似标签的项目中使用......
<pageElements:header/>
它的自定义标签方面很简单,我创建了一个页眉标签,它提供了样板 html 标记,其中包含一些内容文本。
我遇到的问题是他们想要一些图像打包在罐子中,用于徽标等。显然,如果我在标签中放入类似...
<img alt="logo" src="images/logo.png"/>
...的内容,它会正确呈现,但会在使用图像标签的项目上下文中查找。它不存在,因为它位于包含标签定义的 jar 文件内的 resources/images 目录中。
有谁知道我可以将图像打包在包含标签定义的 jar 文件中,然后在标签中引用它,以便当项目使用标签时...
<pageElements:header/>
...它可以正确呈现文本和图像?
本质上我需要知道的是图像应该保存在 jar 文件中的哪个位置,以及如何在定义标签内容的 tagx 文件中引用它们。
非常感谢,
马克
I'm doing some work for a client and they have a common web tag jar file project that they use in various projects. They've asked me to make a header and footer tag that they can use in projects using a tag something like...
<pageElements:header/>
The custom tag aspect of it is simple and I have created a header tag which provides boiler plate html markup comprising of some text.
The problem I'm having is that they want some images packaged up in the jar for things like logos and so on. Obviously if I put something like...
<img alt="logo" src="images/logo.png"/>
...in the tag it's rendered correctly but looks in the context of the project that's using the tag for the image. It doesn't exist as it's in the resources/images directory within the jar file containing the definitions of the tags.
Does anyone know of a way I can package an image in the jar file containing the tag definitions and then refer to it in the tag so that when the project uses the tag...
<pageElements:header/>
...it renders the text and the images correctly?
Essentially what I need to know is where in the jar file should the images be kept and how do I refer to them in the tagx file defining the tag content.
Many thanks,
Mark
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Servlet 3.0 规范指出:
因此,您可以将图像放在 jar 中的 META-INF/resources 下,它们将像直接在战争中一样被提供。
以前版本的规范不提供这种可能性,因此您必须使用 servlet 或过滤器来实现它。 Spring MVC 和 Struts2 本身就提供了这一点。我不知道其他框架。
The servlet 3.0 specification says:
So you can place your images in your jar, under META-INF/resources, and they will be served as if they were directly in the war.
Previous versions of the spec don't provide this possibility, so you'll have to use a servlet or filter to implement it. Spring MVC and Struts2 provide this natively. I don't know about other frameworks.