approaches. The following deployment (Web page design) descriptor fragment illustrates a

approaches. The following deployment descriptor fragment illustrates a filter mapping to a single servlet called MyExampleServlet: MyLoggingFilter MyExampleServlet Every time the web container receives a request for the MyExampleServlet resource, the doFilter( )method in the LoggingFilter class will be invoked. The following XML fragment illustrates how the example filter can be mapped to all requests sent to the web application: MyLoggingFilter /* The filter mapping in this case will map all requests to the MyLoggingFilter because every request URI will match the “/*” URL pattern. 15.2.2.3 Packaging the filter The final step is to package the filter class with the rest of the resources of the web application. As with any other Java resource that is part of a web application, the filter class must be bundled with the WAR file and able to be loaded by the web application’s class loader. In most cases, the filter class should be placed under the WEB-INF/classes directory for the web application. Filter classes may also be inserted into a JAR file and placed in the WEB-INF/lib directory. 15.2.3 Using Event Listeners Web application event listeners are Java classes that implement one or more of the servlet event- listener interfaces. Event listeners support event notifications for changes in state in the ServletContextand HttpSession objects. Event listeners that are bound to the ServletContext support changes at the application level, while those that are bound to the HttpSession objects are notified for state changes at the session level. Multiple listeners can be set up for each event type, and the servlet developer may offer a preference regarding the notification order for the listeners based on event type. Tables Table 15-1 and Table 15-2 list the event types and event-listener interfaces available to the servlet developer. Table 15-1. ServletContext application events and listener interfaces Event type Description Listener interface Lifecycle The ServletContext is about to service the first request or is about to be shut down by the servlet ServletContextListener
You want to have a cheap webhost for your apache application, then check apache web hosting services.

Leave a Reply