This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
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.
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.
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.
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
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
posted
0
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: 1860
posted
0
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: 1860
posted
0
Originally posted by Simon Brown: ...I've been given permission to publish a short extract on my website.