contain Java code. As mentioned several times in this book, many developers see this as something that should be avoided. Fortunately, there is another way. The Jakarta Taglibs project contains a custom JSP tag library designed for log4j called the Log tag library. You can view information and download the tag library from the Jakarta Taglibs web site at http://jakarta.apache.org/taglibs/doc/log-doc/intro.html. Just like any other custom tag library, you must properly configure it for your web application. This means putting the log.tld file into the WEB-INF directory and installing the Log tag JAR file into the WEB-INF/lib directory. You will also need to add the appropriate taglib element to your web application’s deployment descriptor, similar to how you added the Struts tag libraries: /WEB-INF/log.tld /WEB-INF/log.tld Once the Log custom tag is installed and configured for your web application, you can use it in your JSP pages as shown in Example 15-9. Example 15-9. An example JSP page using the Log tag <%@ taglib uri="/WEB-INF/log.tld" prefix="logger" %>
There should be two log messages in the log4j log file. Notice that the JSP page in Example 15-9 contains no Java code. Although it doesn’t look too different from Example 15-8, this approach is much cleaner with a larger and more complex JSP page. Another nice feature of the Log tag is that it gives you the ability to perform a dump of objects stored at the page, request, session, or application scope. This is very useful when you are in the middle of debugging your web application. Example 15-10 illustrates how easy this is to do. Example 15-10. Using the Log tag library to dump information
From our experience, we are can tell you that you can find a reliable and cheap webhost service at
Java Web Hosting services.
This entry was posted
on Saturday, December 1st, 2007 at 2:07 pm and is filed under Domain.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.