Apache Tiles 2.1.4 与 CSS

发布于 2024-08-20 11:34:07 字数 1166 浏览 3 评论 0原文

我正在使用 Apache Tiles 2.1.4 和 Spring MVC 3。我已经成功地将它们配置在一起,一切正常。我的下一步是添加 CSS,这就是我遇到的问题 - 这很可能是一个简单的问题,但我无法让我的模板 jsp 获取 css。

来自我的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>

片段 来自我的模板jsp 的片段 (baseLayout.jsp)

<link type="text/css" rel="stylesheet" href="<%=request.getContextPath()%>/WEB-INF/css/displayTagTable.css"/>

来自我的CSS 的片段:

body {
background-color: red;

}

我使CSS 尽可能简单,只是为了检查我的jsp 是否选取了CSS 文件。

我还检查了我的 css 文件是否位于正确的位置 - 但我的 jsp 文件没有获取 css 文件。有人可以帮忙吗?

任何帮助将不胜感激。

谢谢, 扎汉吉尔

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.

Snippet from my 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)

<link type="text/css" rel="stylesheet" href="<%=request.getContextPath()%>/WEB-INF/css/displayTagTable.css"/>

Snippet from my 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.

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?

Any help will be much appreciated.

Thanks,
Zahanghir

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

许仙没带伞 2024-08-27 11:34:07

WEB-INF 中的文件不直接通过公共 URL 提供。 Spring 和tiles 能够以编程方式间接从WEB-INF 提供JSP 文件。

您能否尝试将 css 目录移至 WebContent 并更新您的 标记的 href 属性?

在您开始工作后,我有一个建议。如果您在 JSP 顶部包含此页面指令,则可以使用 Tiles 标签:

<%@taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles"%>

如果您愿意,这允许您将 CSS 路径作为属性存储在 tiles-defs.xml 中,并检索它来自带有标签的 JSP:

<link type="text/css" rel="stylesheet"
    href="<tiles:getAsString name="IDENTIFIER_HERE"/>"/>

您的 CSS URL 将替换tiles 标签。您可以在多个 Tiles 定义中使用此 CSS 路径。

其余的 Tiles 标签记录在此处:Tiles 标签参考表

Files within WEB-INF aren't served directly through public URLs. Spring and tiles are able to indirectly serve JSPs files from WEB-INF programatically.

Can you please try moving the css directory into WebContent and updating your <link> tag's href attribute?

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:

<%@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:

<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.

The rest of the Tiles tags are documented here: Tiles Tag Reference Sheet

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文