The Pragmatic Craftsman         :: Simplicity from complexity :: | About Me |

You are here: The Pragmatic Craftsman > Java

Go to: « Ambler on Best Programmers | Holub on Simplicity »

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.


Comments

That's pretty slick.

· December 8, 2004 ·


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

· January 4, 2005 ·


Post a comment









Remember personal info?







Go to:
   « previous entry: Ambler on Best Programmers
   » next entry: Holub on Simplicity

Random Quote

Search

 

Topics

Architecture & Design :12
Better Coder :29
Books :43
Books Recommended :18
Buzzwords :5
Career :25
Craftsmanship :15
Java :15
Quotes :25
Recommended :9
Software Engineering :3
Uncategorized :33
Web Development :1

Archive

May 2008 (1)
April 2008 (2)
March 2008 (1)
February 2008 (1)
January 2008 (2)
November 2007 (1)
October 2007 (3)
August 2007 (3)

...since January 2002

Currently Reading


:: See list of books I finished reading

Info

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