I have a block of JSP code that needs to be used in several places (basically a widget that several pages use). What's a good way to modularize this? I'd rather not put it in an object since string manipulation of HTML gets ugly. Using <%@ include file="foo.jsp"%>
is problematic because we wind up having implicit global vars.
views:
351answers:
3
+9
A:
You can create a simple tag and use it anywhere you want your widget. A tag is a reusable object that you can use in any of your JSP's.
Please see http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/JSPTags.html.
Bogdan
2008-11-11 17:49:43
+4
A:
Separate the JSP out into its own file and include it (JSP Includes, Tiles Includes, etc)
Can you create a Tag Lib incorporating the functionality?
JeeBee
2008-11-11 17:50:18
+1
A:
In JSP 2, custom tags were improved. Here's a good article on them.
Previously, JSP isn't very good at modularizing code, includes and tag libs, the two options you discounted, are about it. Custom tags before JSP 2, which Bogdan points you to, are powerful, but have an overhead.
sblundy
2008-11-11 18:09:37