JSP Tag Libraries

Скачать в pdf «JSP Tag Libraries»
9.3.4 Our tag library in action

We can now take a look at a few JSP fragments that use the tag. You’ll recognize the following JSP fragment from earlier in this chapter; and it will prove even more useful based on what we’ve just learned. This fragment shows how the tag is employed

in testing a boolean value; the conditions we use are eq true and eq false, meaning equals true and equals false. We are not doing a simple if-eise (we actually can’t), but instead are asking about two negatives.

Listing 9.8 Using the conditional tags with a boolean value

<% Boolean b = new Boolean(true); %> <cond:with object=»<%= b %>»>

The value is

<cond:test condition=»eq true»> true


<cond:test condition=»eq false»> false



You may wonder about the fact that in
listing 9.8 we generated our object in a scriptlet (about the easiest way to pass a value to the tag), but don’t let it concern you. We could get this value from anywhere in the JSP environment (e.g., we could get this value from a bean) and our tag would work equally well.

Another sample JSP fragment shows a more complex scenario in which the developer grabs the User-Agent header and checks to see what type of client is being served.

Listing 9.9 A complex usage of the conditional tags

<cond:with object=»<%= request %> property=»header» index=»User-Agent» multichoice=»true»> C

Your browser is IE?

<cond:test condition=»contains MSIE»>


Скачать в pdf «JSP Tag Libraries»