1

In the Spring MVC application project current I am working on, We have number of JSP files in our View tier. Within each we have a Html element containing properties like page title, keywords, stylesheet links, and etc.

As our JSP files are growing in quantity, I would like to avoid copying and pasting common parts in HTML head element such as title and meta informations. In addition page title and keywords meta may change in future and I am not planning to open each JSP file to propagate the change.

What I first came up with was to create a .properties file and use JSTL fmt:message tag in following manner:

<fmt:message key="villap.title" var="title" />
<fmt:message key="villap.keywords" var="keywords" />

<head>
    <title>${title}</title>
    <meta name="keywords" content="${keywords}"/>
</head>

Still I have to place this same code segment in each one of my JSP files.

What is the best practice here? Should I put the HTML head section all together in a separate JSP file and import it every time?

mdoust
  • 429
  • 1
  • 4
  • 20

1 Answers1

3

If you do not want to repeat the same HTML again and again, you should use a templating framework (Apache Tiles, SiteMesh, Velocity and Freemarker are some examples). The Spring Reference calls these frameworks view technologies, and it has some information on their usage.

Persanaly, I use JSP tag files instead of any third-party framework and I am very happy with it. This answer provides all technical detail that you need to know to start using it.

Community
  • 1
  • 1
Alexey
  • 2,542
  • 4
  • 31
  • 53