外文翻译---将servlet和jsp组合使用-jsp程序(编辑修改稿)内容摘要:
n, so if you39。 re using a container that doesn39。 t yet support this version of the specification, I39。 m afraid you39。 re 7 out of luck. Filters A filter is a ponent that can intercept a request targeted for a servlet, JSP page, or static page, as well as the response before it39。 s sent to the client. This makes it easy to centralize tasks that apply to all requests, such as access control, logging, and charging for the content or the services offered by the application. A filter has full access to the body and headers of the request and response, so it can also perform various transformations. One example is pressing the response body if the AcceptLanguage request header indicates that the client can handle a pressed response. A filter can be applied to either a specific servlet or to all requests matching a URL pattern, such as URLs starting with the same path elements or having the same extension. Listeners Listeners allow your application to react to certain events. Prior to Servlet , you could handle only session attribute binding events (triggered when an object was added or removed from a session). You could do this by letting the object saved as a sessionattribute(using the () method)implement the HttpSessionBindingListener interface. With the new interfaces introduced in the version of the specification, you can create listeners for servlet context and session lifecycle events as well as session activation and passivation events (used by a container that temporarily saves session state to disk or migrates a session to another server). A new 8 session attribute event listener also makes it possible to deal with attribute binding events for all sessions in one place, instead of placing individual listener objects in each session. The new types of listeners follow the standard Java event model. In other words, a listener is a class that implements one or more of the listener interfaces. The interfaces define methods that correspond to events. The listener class is registered with the container when the application starts, and the container then calls the event methods at the appropriate times. Initializing Shared Resources Using a Listener Beans like this typically need to be initialized before they can be used. For instance, they may need a reference to a database or some other external data source and may create an initial information cache in memory to provide fast access even to the first request for data. You can include code for initialization of the shared resources in the servlet and JSP pages that need them, but a more modular approach is to place all this code in one place and let the other parts of the application work on the assumption that the resources are already initialized and available. An application lifecycle listener is a perfect tool for this type of resource initialization. This type of listener implements the interface, with methods called by the container when the application starts and when it shuts down. Picking the Right Component Type for Each Task The Project Billboard application introduced is a fairly plex application. Half the 9 pages are pure controller and business logic processing, it accesses a database to authenticate users, and most pages require access control. In real life, it would likely contain even more pages, for instance, pages for access to a shared document archive, time schedules, and a set of pages for administration. As the application evolves, it may bee hard to maintain as a pure JSP application. It39。 s easy to forget to include the access control code in new pages. This is clearly an application that can benefit from using a bination of JSP pages and the ponent types defined by the servlet specification for the MVC roles. Let39。 s look at the main requirements and see how we can map them to appropriate ponent types: Database access should be abstracted, to avoid knowledge of a specific data schema or database engine in more than one part of the application: beans in the role of Model can be used to acplish this. The database access beans must be made available to all other parts of the application when it starts: an application lifecycle event listene。外文翻译---将servlet和jsp组合使用-jsp程序(编辑修改稿)
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。
用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。