| Author |
Dynamic HTML page titles using jsp
|
guru naan
Greenhorn
Joined: Feb 21, 2002
Posts: 6
|
|
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
Joined: May 20, 2002
Posts: 75
|
|
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
Joined: May 10, 2001
Posts: 3244
|
|
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 ]
|
Dave
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56179
|
|
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 ]
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
James Carman
Ranch Hand
Joined: Feb 20, 2001
Posts: 580
|
|
|
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).
|
James Carman, President<br />Carman Consulting, Inc.
|
 |
 |
|
|
subject: Dynamic HTML page titles using jsp
|
|
|