• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

Dynamic HTML page titles using jsp

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Sheriff
Posts: 67642
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic