Anthony
Anthony

Reputation: 12736

Creating custom JSP tags

In my JSP there is code:

<img src="<c:out value="${requestScope['img_url']}"/>"/>

I would like to replace it with something like this:

<xyz:img src="${requestScope['img_url']}"/>

I tried Struts Taglib, but it requires Struts. Is there any other alternative?

Upvotes: 2

Views: 2190

Answers (2)

Beau Grantham
Beau Grantham

Reputation: 3456

This is just custom JSP tags. There is a great Sun/Oracle tutorial (archived page) and lots of other great resources out there.

Here are some of the Oracle's resources:

Upvotes: 3

Anthony
Anthony

Reputation: 12736

This article helped me to find a very simple solution: Encapsulating Reusable Content Using Tag Files

  1. Create file WEB-INF/tags/img.tag
  2. Add to JSP this header: <%@taglib tagdir="/WEB-INF/tags" prefix="xyz" %>
  3. Just use it :)

Upvotes: 1

Related Questions