aspose file tools*
The moose likes JSP and the fly likes JSP Components Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP Components" Watch "JSP Components" New topic
Author

JSP Components

Grant Morris
Greenhorn

Joined: Aug 08, 2001
Posts: 8
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.
David Hibbs
Ranch Hand

Joined: Dec 19, 2002
Posts: 374
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.


"Write beautiful code; then profile that beautiful code and make little bits of it uglier but faster." --The JavaPerformanceTuning.com team, Newsletter 039.
Marty Hall
Author
Ranch Hand

Joined: Jan 02, 2003
Posts: 111
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


Java training and consulting<br /><a href="http://www.coreservlets.com/" target="_blank" rel="nofollow">http://www.coreservlets.com/</a>
Simon Brown
sharp shooter, and author
Ranch Hand

Joined: May 10, 2000
Posts: 1913
    
    6
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
Tony Walters
Ranch Hand

Joined: Feb 13, 2003
Posts: 54
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

Joined: Dec 19, 2002
Posts: 374
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
Ranch Hand

Joined: May 10, 2000
Posts: 1913
    
    6
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
Ranch Hand

Joined: May 10, 2000
Posts: 1913
    
    6
Originally posted by Simon Brown:
...I've been given permission to publish a short extract on my website.

Here's that link.
Simon
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP Components
 
Similar Threads
Forms in servlet
JSP's
Use Bean more than one time
AJAX Problem in responseText
Is it possible to integrate the existing J2EE application with grails?