jspjsp-tagstaglib

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?


Solution

  • 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 :)