在 Spring+Tiles2 应用程序中设置 HTML 标题的最佳方法?

发布于 2024-07-20 22:36:16 字数 856 浏览 6 评论 0原文

我的 Spring Web 应用程序使用 Tiles 作为视图技术,但存在可用性问题。 目前,所有页面都显示相同的 HEAD_TITLE 并且 PAGE_TITLE 是特定于页面的:

 <html>
 <head><title>HEAD_TITLE</title></head>
 <body>
 <h1>PAGE_TITLE</h1>
 </body>
 </html>

这是一个主要的可用性问题,因为浏览器历史记录会列出应用程序的所有不同页面相同的标题。 所有页面的 HEAD_TITLE 都相同的原因是我还没有找到合理的方法来使用 PAGE_TITLE 作为 HEAD_TITLE

在大多数情况下,PAGE_TITLE 来自带有 标记的消息包,并且 一些参数被传递给它。 Tiles 布局是这样的,此时 HEAD_TITLE 应该已设置,因为 web 应用程序的所有页面都使用相同的通用布局,该布局定义了 元素。页面以及其他内容。

有什么建议如何解决这个可用性问题吗? 我是否应该在 Spring 控制器中为所有页面设置“pageTitle”请求属性,并将其用作 PAGE_TITLEHEAD_TITLE? 或者是否可以以某种方式在页面特定的 JSP 中设置 HEAD_TITLE?

I have a usability problem in my Spring webapp which uses Tiles as the view technology.
At the moment all of the pages display the same HEAD_TITLE and the PAGE_TITLE is page specific:

 <html>
 <head><title>HEAD_TITLE</title></head>
 <body>
 <h1>PAGE_TITLE</h1>
 </body>
 </html>

This is a major usability problem as the browsers history lists all different pages of the application with the same title. The reason why the HEAD_TITLE is same for all pages is that I haven't found a reasonable way to use the PAGE_TITLE as the HEAD_TITLE.

In most cases the PAGE_TITLE comes from a message bundle with <fmt:message /> tag and
some parameters are passed to it. The Tiles layout is such that the HEAD_TITLE should be already set at that point because all pages of the webapp use the same common layout which defines the <HEAD> elements of the pages amongst other stuff.

Any suggestions how to fix this usability problem? Should I set a "pageTitle" request attribute in my Spring controllers for all pages and use that as the PAGE_TITLE and also as the HEAD_TITLE? Or is it possible to somehow set the HEAD_TITLE in the page specific JSP?

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

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

发布评论

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

评论(1

[浮城] 2024-07-27 22:36:16

创建一般定义并定义 headTitle 和 pageTitle 属性。

<definition name="threeColumnLayout" template="/WEB-INF/ThreeColumnLayout.jsp" >
    <put-attribute name="headTitle" value="" />
    <put-attribute name="pageTitle" value="" />
    <put-attribute name="left" value="/WEB-INF/left.jsp" />
    <put-attribute name="middle" value="" />
    <put-attribute name="right" value="/WEB-INF/right.jsp" />
</definition>

在更具体的定义中设置适当的值。

<definition name="/user/new" extends="threeColumnLayout">
    <put-attribute name="headTitle" value="Administration" />
    <put-attribute name="pageTitle" value="Create User" />
    <put-attribute name="middle" value="WEB-INF/views/UserCreate.jsp" />
</definition>

使用 标签在 jsp 页面中检索此类值。

<head>
    <title><tiles:getAsString name="headTitle"/></title>
</head>
<body>
    <h1>
        <title><tiles:getAsString name="pageTitle"/></title>
    </h1>
</body>

参考:- http://tiles.apache.org/framework/ tiles-jsp/tagreference.html#tiles:getAsString

Create a general definition and define headTitle and pageTitle attributes.

<definition name="threeColumnLayout" template="/WEB-INF/ThreeColumnLayout.jsp" >
    <put-attribute name="headTitle" value="" />
    <put-attribute name="pageTitle" value="" />
    <put-attribute name="left" value="/WEB-INF/left.jsp" />
    <put-attribute name="middle" value="" />
    <put-attribute name="right" value="/WEB-INF/right.jsp" />
</definition>

Set appropriate values in more specific definition.

<definition name="/user/new" extends="threeColumnLayout">
    <put-attribute name="headTitle" value="Administration" />
    <put-attribute name="pageTitle" value="Create User" />
    <put-attribute name="middle" value="WEB-INF/views/UserCreate.jsp" />
</definition>

Use <tiles:getAsString /> tag to retrieve such values in jsp page.

<head>
    <title><tiles:getAsString name="headTitle"/></title>
</head>
<body>
    <h1>
        <title><tiles:getAsString name="pageTitle"/></title>
    </h1>
</body>

Reference:- http://tiles.apache.org/framework/tiles-jsp/tagreference.html#tiles:getAsString

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