|
|
Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
Page 3 of 3
You should now compile the above class, ensuring that you have the Servlet/JSP classes in your classpath. Those can be found in TOMCAT_HOME/lib/servlets.jar.
web-inf directory. Open up the web.xml file and insert the following XML fragment. The ordering of XML elements in the file is important,
so the fragment below should be placed before or after the existing example taglib. <taglib>
<taglib-uri>
http://www.mycompany.com/taglib
<taglib-uri>
<taglib-location>
/WEB-INF/taglib.tld
<taglib-location>
</taglib>
That tells the Web application where to find the taglib descriptor and the URI that refers to the taglib. Again, that doesn't have to be a real URI, but it should be the same as the one specified in the taglib.tld file that you created above.
TOMCAT_HOME/webapps/examples).<html> <head> <%@ taglib uri="http://www.mycompany.com/taglib" prefix="examples" %> </head> <body> The file is <examples:size uri="/jsp/index.html"/>. </body> </html>
The taglib directive tells the JSP engine that your JSP wishes to use a taglib referred to by the specified URI. The taglib
directive also takes a prefix that tags on the page will use. For the sake of this example, I'll be using the examples prefix.
On the JSP, your tag consists of the prefix (like an XML namespace), the tag name, and any attributes. It's written by using normal XML notation, and the example above uses the shorthand for combining the opening and closing tags. The URI that you pass your tag just points to an HTML file provided with the JSP examples.
All you need now is to start up Tomcat and request the JSP from your browser. What you should notice is that your custom tag has been completely processed and substituted with the HTML that it generated dynamically. If you take a look at the HTML source via the browser, you should also notice that no trace of your tag remains.
Although there's a lot more to taglibs than has been presented here, the article aimed to give you a good starting point from which to explore further and begin to develop your own taglibs. Custom tags are a very powerful addition to the current JSP specification and a great mechanism for wrapping up reusable functionality on your JSPs.
Read more about Core Java in JavaWorld's Core Java section.