Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dynamic HTML page titles using jsp

 
guru naan
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
JSP newbie here. How am I supposed to create dynamic html page titles with JSP. I'm using page includes for my header/footer and would like to create a variable for my page title that would be different in each page.
So for my main content pages you would have something like
maincontent.jsp
<jsp:include page="includes/blocks/header.jsp" flush="true"/>
String pageTitle = "This is a page title";
this is where my main content would go.
<jsp:include page="includes/blocks/footer.jsp" flush="true"/>
and then in header.jsp
I would have to have something that calls the title variable
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> out.println(pageTitle) </title>
HOWEVER the above does not work. Does anyone know how to do this
Thanks in advance
 
Mark Stein
Ranch Hand
Posts: 75
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try putting the string title at the top of the page, before you start any of the HTML. Put the header somewhere below that (where it fits into the HTML).
MS
 
Dave Vick
Ranch Hand
Posts: 3244
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guru
What you want to do is set the title string before you include the header page then pass the string into the header as a parameter.

maincontent.jsp

Then in your header page you can get the parameter passed in and use it like this:

hope that helps you out
[had to put a space in the jsp parameter tag after the : so a smiley wouldn't pop up]
[ August 20, 2002: Message edited by: Dave Vick ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64171
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving the variable would not work unless you change the jsp:include to a include directive (which in-lines the sub-page rather than making a request into it).
What you can do is to use the jsp: param tag to pass the title as a request parameter to your header page.
hth,
bear
P.S. Drat, Dave's response beat mine by a minute!
[ August 20, 2002: Message edited by: Bear Bibeault ]
 
James Carman
Ranch Hand
Posts: 580
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instead of using a <jsp:include> for headers and footers, try using a more robust template engine like the one that comes with Struts (or the newer Struts Tiles library).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic