带有 CSS 的 Apache Tiles 2.1.4
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2222429/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Apache Tiles 2.1.4 with CSS
提问by Zahanghir
I am using Apache Tiles 2.1.4 with Spring MVC 3. I have managed to configure these together and everything works fine. My next step is to add CSS and this is where I am having an issue - this is most probably a simple one but I can't get my template jsp to pick up the css.
我将 Apache Tiles 2.1.4 与 Spring MVC 3 一起使用。我设法将它们配置在一起,一切正常。我的下一步是添加 CSS,这就是我遇到问题的地方 - 这很可能是一个简单的问题,但我无法让我的模板 jsp 获取 css。
Snippet from my tiles-defs.xml
来自我的tiles-defs.xml 的片段
<definition name="baseLayout" template="/WEB-INF/tiles/baseLayout.jsp">
<put-attribute name="title" value="Template"/>
<put-attribute name="header" value="/WEB-INF/tiles/header.jsp"/>
<put-attribute name="styles" value="base.css"/>
<put-attribute name="subheader" value="/WEB-INF/tiles/subheader.jsp"/>
<put-attribute name="menu" value="/WEB-INF/tiles/menu.jsp"/>
<put-list-attribute name="bodyItems">
<add-attribute value="/WEB-INF/tiles/body.jsp"/>
</put-list-attribute>
Snippet from my template jsp (baseLayout.jsp)
来自我的模板 jsp (baseLayout.jsp) 的片段
<link type="text/css" rel="stylesheet" href="<%=request.getContextPath()%>/WEB-INF/css/displayTagTable.css"/>
Snippet from my css:
来自我的 css 的片段:
body {
background-color: red;
}
}
I have kept the css as simple as possible just to check if my jsp picks up the css file.
我让 css 尽可能简单,只是为了检查我的 jsp 是否选择了 css 文件。
I have also checked that my css file is in the correct location - but my jsp file is not picking up the css file. Can someone help?
我还检查了我的 css 文件是否在正确的位置 - 但我的 jsp 文件没有选择 css 文件。有人可以帮忙吗?
Any help will be much appreciated.
任何帮助都感激不尽。
Thanks, Zahanghir
谢谢,扎汉吉尔
采纳答案by Abboq
Files within WEB-INFaren't served directly through public URLs. Spring and tiles are able to indirectly serve JSPs files from WEB-INFprogramatically.
其中的文件WEB-INF不直接通过公共 URL 提供。Spring 和 tile 能够以WEB-INF编程方式间接提供 JSP 文件。
Can you please try moving the css directory into WebContent and updating your <link>tag's hrefattribute?
您能否尝试将 css 目录移动到 WebContent 并更新您的<link>标签href属性?
After you get that working, I have a suggestion. You can use Tiles tags if you include this page directive at the tops of your JSPs:
在你开始工作后,我有一个建议。如果在 JSP 的顶部包含此页面指令,则可以使用 Tiles 标记:
<%@taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles"%>
If you want, this allows you to store your CSS path as an attribute in tiles-defs.xml, and retrieve it from your JSPs with the tag:
如果需要,这允许您将 CSS 路径作为属性存储在 中tiles-defs.xml,并使用标记从 JSP 中检索它:
<link type="text/css" rel="stylesheet"
href="<tiles:getAsString name="IDENTIFIER_HERE"/>"/>
Your CSS URL will replace the tiles tag. And you could use this CSS path across multiple Tiles definitions.
您的 CSS URL 将替换tiles 标签。您可以在多个 Tiles 定义中使用此 CSS 路径。
The rest of the Tiles tags are documented here: Tiles Tag Reference Sheet
其余的 Tiles 标签记录在此处:Tiles Tag Reference Sheet

