Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to modularize a block of JSP code

Tags:

java

jsp

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.

like image 949
timdisney Avatar asked Nov 11 '08 17:11

timdisney


2 Answers

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.

like image 64
Bogdan Avatar answered Sep 19 '22 12:09

Bogdan


  1. Separate the JSP out into its own file and include it (JSP Includes, Tiles Includes, etc)

  2. Can you create a Tag Lib incorporating the functionality?

like image 25
JeeBee Avatar answered Sep 18 '22 12:09

JeeBee