1 on 1 web hosting - } public void destroy( ){ // Remove any

} public void destroy( ){ // Remove any resources to the logging framework herelog( “LoggingFilter destroyed” ); } protected void log( String message ) { getServletContext( ).log(”LoggingFilter: ” + message ); } protected ServletContext getServletContext( ){ return this.servletContext; } } Just as you must be careful with multiple threads in Java servlets, you must be careful not to violate any thread-safety practices with filters. The servlet container may send concurrent threads to a single instance of a filter class, and you must ensure that you don’t do anything to cause problems between the threads. In other words, no client-specific data should be stored in instance variables. Local variables are fine, just as they are in Java servlets, because they are stored on the stack rather than the heap. 15.2.2.2 Declaring the filter in the deployment descriptor The second step in creating a servlet filter is to configure the proper elements in the deployment descriptor for the web application. As you learned in Chapter 4, the name of the deployment descriptor file for a web application is web.xml. The first step in setting up the filter declaration in the web application’s deployment descriptor is to create the actual filter elements. Chapter 4 describes the filter element in detail. The following deployment descriptor fragment illustrates how it looks using the LoggingFilter class from the previous section: MyLoggingFilter LoggingFilter
log_file_name log.out
You can also optionally specify initialization parameters, icons, a description, and a display label. See Chapter 4 for more details on the attributes of the filter element. Once the filter element is added, you need to add a filter-mapping element that will associate or link the specified filter to a servlet or static resource in the web application. Filters can be applied to a single servlet or to groups of servlets and static content, using two distinct mapping
You need excellent and relaible webhost company to host your web applications? Then pay a visit to Inexpensive Web Hosting services.

Leave a Reply