Dorrell
Dorrell

Reputation: 3

Any solution to override page title on a JSP page

<jsp:include page="categories/sub-category/${param.ID}.jsp" flush="true" />

The simplest way to put it is to find ANY way for the the jsp's under 'sub-category' (that paramID calls) to each have their own unique page title. Whether that's jstl, java, or what have you, I'm not sure... so the only requirements are 1) It works 2) SEO-friendly

I know of this way:

<script>
    document.title = "My Title";
</script>

with the scripts, but this is bad for SEO (also the main reason for this is so that Disqus 'related discussions' will show up with unique page titles).

I've also seen this way:

<head><title><%= param.name %></title></head>

but this left me with an "param cannot be resolved to a variable" error. Maybe I am doing something wrong? Thanks for any constructive help. If you need any more info let me know...

This is how it looks in the address bar ...

http://localhost:8080/root/categories.jsp?ID=test-page

So from the answer, the code to put in test-page.jsp is

<head><title>${param.name}</title></head>  correct?

How to write inside test-page.jsp the value of the title as a string? So inside test-page.jsp have it say "title of the test page"

Upvotes: 0

Views: 5345

Answers (1)

KV Prajapati
KV Prajapati

Reputation: 94645

You can use <jsp:param> to pass parameters with <jsp:include> and <jsp:forward> actions.

<jsp:include page="categories.jsp" flush="true">
   <jsp:param name="id" value="test-page.jsp"/>
   <jsp:param name="title" value="Title of test page"/>
</jsp:include>

And code/markup in categories.jsp should be,

<head>
  <title>${param.title}</title>
</head>

Upvotes: 1

Related Questions