How to transfer attribute from several JSP pages to be displayed in a Tiles template page
I have a file pageLayout.jsp, where the basic structure of each page is laid out, including an HTML title.
<title>Project Name</title>
Instead of having a static title (like above), I would like to transfer the value of the title of each page to the template. For example, if the JSP page using the template has an H1 element displayed like this
<h1>
<spring:message code="page.manufacturer.list.title" />
</h1>
, I would like to transfer the value of the spring:message tag above to be displayed within the title tag in the JSP template. The spring message should be transferred from several different pages (each containing a different spring message) to the one template page.
What is the best way to开发者_如何学Python achive this?
mylayout.jsp
<html>
<head>
<title><tiles:getAsString name="title"/></title>
</head>
<body>
<tiles:insertAttribute name="body" />
</body>
</html>
somepage.jsp
<tiles:insertDefinition name="mylayout">
<spring:message code="example.message" var="title"/>
<tiles:putAttribute name="title" value="${title}"/>
<tiles:putAttribute name="body">
...
</tiles:putAttribute>
</tiles:insertDefinition>
Wouldn't this work?
<title><spring:message code="page.manufacturer.list.title" /></title>
Pass it (in)directly as request parameter. Really, there's no better way since HTTP is stateless. Putting it in session without a request parameter based key may work for single tab/window, but it may end up in undesired results when using multiple tabs/windows in same browser session.
精彩评论