The Pragmatic Craftsman :: Simplicity from complexity : by Stanley Kubasek ::

JSP 2.0 Tags

Did you know that you could write a JSP tag without writing a single line of Java code? I didn’t. I was surprised today when I discovered that. I’m going to show you how easy it is. Let’s take an anchor tag (<a href=”">link</a>). If you don’t get to write it very often, you might forget the exact syntax. Why not write a simple tag? This would make things easier.

Here is a simple tag, link.tag:

<%@ attribute name="address" required="true" description="Location"%><%@ attribute name="title" required="false" description="Label"%><a href="${address}">${title}</a>

That’s it! You’ve got yourself a jsp tag. Here is an example, link.jsp, of its actual usage.

<%@ taglib tagdir="/WEB-INF/tags/" prefix="tags"%><html><body><p><tags:link address="http://aol.com" title="aol.com" /></p></body></html>

How about that? That’s one cool feature of JSP. Read some other cool stuff about JSP 2.0 here.

Another cool feature is the use of JSTL, which is a pre-defined tag library for common tasks. What tasks? Access to request parameters, access to beans, logic, and other. If you use JSTL, your JSP pages are without Java code. You use a simple scripting language EL (Expression Language) for that. After all, JSP is a view. It should not have any Java code. Period. If you are considering JSP, or if you want to move to JSP, use JSTL. It will make your life much easier. Plus, you’re not going to fall into the trap of doing most of your business logic inside your page. JSTL gives you a seperation of layers by default.

Here is a link to very good JSP 2.0 article, Faster Development with JavaServer Pages Standard Tag Library (JSTL 1.0), by Qusay H. Mahmoud.

2 Responses to “JSP 2.0 Tags”

  1. rob says:

    That’s pretty slick.

  2. mib says:

    It’s a great pity, that (my)eclipse cannot handle these custom tags ……

Favorite Quote

Topics

Tags

Archive

Currently Reading

Info

© 2001-2019 Stanley Kubasek About me :: Contact me

Me on Twitter

»see more

Recent Entries