• 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:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

JSP Components

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure if you can do this or not, but it would seem to be useful...
I'm looking for a way to create something similar to a custom tag that will hold a chunk of JSP so that you can re-use often used chunks of JSP among many pages without having to cut and paste and thus creating a maintainence nightmare. Are there any patterns or best practices way to do this?
Thanks for the help.
 
Ranch Hand
Posts: 374
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's part of what custom tags are for!
Your other option is a jsp:include directive, which tells the current page to include the results of another one in the output of the first. If you do a search on jsp:include on google, sun, or here you should have no problem finding information on it.
 
Author
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I'm looking for a way to create something similar to a custom tag that will hold a chunk of JSP so that you can re-use often used chunks of JSP among many pages without having to cut and paste and thus creating a maintainence nightmare.


That's what jsp:include is for. See http://courses.coreservlets.com/Course-Materials/Se10-Including-Files.pdf or Chapter 12 of http://pdf.coreservlets.com/ or
Cheers-
- Marty
 
sharp shooter, and author
Posts: 1913
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thankfully JSP 2.0 has a better answer to this in the form of "tag files". These are basically custom tags that are written using JSP code instead of Java code, meaning that it's much, much easier to template portions of your JSP based site.
Although JSP 2.0 and supporting containers aren't there yet, tag files provide a much more natural interface over "raw" jsp:includes. One of the chapters that I've written for Professional JSP 2.0 covers tag files and I've been given permission to publish a short extract on my website. Once I've sorted out the formatting I'll let you know the URL.
Cheers
Simon
 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A common way to include bits of jsp in any number of web pages, while keeping the actual jsp in one place, is with includes. For example, say i had a header that i wanted repeating on every page, i could write the code for this header in a file called 'header.jsp',then include it on a web page by saying ...
<%@ include file="header.jsp" %>
This would cause the jsp engine to import the contents of the file when it is compiling its pages.
 
David Hibbs
Ranch Hand
Posts: 374
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Tony Walters:
A common way to include bits of jsp in any number of web pages...
...This would cause the jsp engine to import the contents of the file when it is compiling its pages.


Common, yes. But it doesn't help with his problem of maintaining the site.
The key phrase is above -- "when it is compiling the pages"
If you modify the included file, it won't get picked up until the next time you touch each page including it.
Before long, someone around here's going to slap me for ranting about this so often...
:roll:
 
Simon Brown
sharp shooter, and author
Posts: 1913
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by David Hibbs:

Before long, someone around here's going to slap me for ranting about this so often...
:roll:


It happens so often though - the JSP compiling thing, not the ranting!
Simon
 
Simon Brown
sharp shooter, and author
Posts: 1913
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Simon Brown:
...I've been given permission to publish a short extract on my website.


Here's that link.
Simon
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic