Lilly
Lilly

Reputation: 69

JSP meta title property doesn't work

In my header.jsp, I have following code:

<head>
    <meta name="description" content="<%= request.getParameter("description") %>" />
    <meta property="og:description" content="<%= request.getParameter("description") %>" />
    <meta property="og:title" content="<%= request.getParameter("title") %>" />
    <meta property="og:type" content="website" />
    <title>Title Website</title>
</head>

<body>
<div id="nav">navigation menu</div>
</body>

On my page "Reservation.jsp", I have following code:

<jsp:include page="includes/header.jsp">
    <jsp:param name="reservation" value="current" />
    <jsp:param name="description" value="Please reserve your place" />
    <jsp:param name="title" value="Please reserve your place" />
</jsp:include>

<div id="content">
content
</div>

<jsp:include page="includes/footer.jsp">
</jsp:include>

When I open the reservation.jsp page in my browser, the title in the tab stays "Title Website" instead of "Please reserve your place".

What the heck is wrong?

Upvotes: 0

Views: 1428

Answers (2)

Keerthivasan
Keerthivasan

Reputation: 12880

You have declared in your header.jsp

<title>Title Website</title>

So, the title shows Title Website

As per the documentation, When an include or forward element is invoked, the original request object is provided to the target page. If you wish to provide additional data to that page, you can append parameters to the request object by using the jsp:param element:

<jsp:include page="..." >
    <jsp:param name="title" value="Please reserve your place"/>
</jsp:include>

You have added a parameter title for include element in the page. that's all. There is no relation with param named title and HTML tag <title>. They are totally different and they have their own purpose. In order to set the param value in title of header.jsp, you need to change it like

<title><%= request.getParameter("title") %></title>

So, that value of title request parameter will be set in the title tag during page creation

Upvotes: 2

Lilly
Lilly

Reputation: 69

Found it, it is

<title><%= request.getParameter("title") %></title>

instead of

<title>Title Website</title>

Upvotes: 1

Related Questions