Servlets FAQ
How do I call one servlet from another servlet?
- use a RequestDispatcher
- use a URLConnection or HTTPClient
- send a redirect
- call getServletContext().getServlet(name) (deprecated, doesn't work in 2.1+)
BookDBServlet database = (BookDBServlet)
getServletConfig().getServletContext().getServlet("YOURSERVLETNAME");
—————
about servlet filters?
The Java Servlet specification version 2.3 introduces a new component type, called a filter. A filterdynamically intercepts requests and responses to transform or use the information contained in the requests or responses. Filters typically do not themselves create responses, but instead provide universal functions that can be "attached" to any type of servlet or JSP page.
Filters are important for a number of reasons. First, they provide the ability to encapsulate recurring tasks in reusable units. Organized developers are constantly on the lookout for ways to modularize their code. Modular code is more manageable and documentable, is easier to debug, and if done well, can be reused in another setting.
Second, filters can be used to transform the response from a servlet or a JSP page. A common task for the web application is to format data sent back to the client. Increasingly the clients require formats (for example, WML) other than just HTML. To accommodate these clients, there is usually a strong component of transformation or filtering in a fully featured web application. Many servlet and JSP containers have introduced proprietary filter mechanisms, resulting in a gain for the developer that deploys on that container, but reducing the reusability of such code. With the introduction of filters as part of the Java Servlet specification, developers now have the opportunity to write reusable transformation components that are portable across containers.
—————
what is servlet Listeners?
—————
difference between servlet filters and servlet Listeners?
Servlet Filter is used for monitoring request and response from client to the servlet, or to modify the request and response, or to audit and log.
Servlet Listener is used for listening to events in a web containers, such as when you create a session, or place an attribute in an session or if you passivate and activate in another container, to subscribe to these events you can configure listener in web.xml, for example HttpSessionListener.
Filetrs are used for pre and post process requests. look at the javax.servlet.Filter in your tomcat/jboss/other container javadoc
Where as the listeners are like triggers that can be attached to events in your app server (let's use the term container here) With listeners you can track application-level, session-level, life-cycle changes, attribute changes etc. The implemented interfaces are javax.servlet.*Listener interface.
Filters are called on a per-request basis and listeners are not. Filetrs have access to request object and listeners don't.
—————
Topic: Servlets FAQ
Date: 23/12/2023
Subject: Mr.
—————
Date: 23/12/2023
Subject: Mr.
—————
Date: 23/12/2023
Subject: Mr.
—————
Date: 23/12/2023
Subject: Mr.
—————
Date: 23/12/2023
Subject: Mr.
—————
Date: 23/12/2023
Subject: Mr.
—————
Date: 23/12/2023
Subject: Mr.
—————
Date: 23/12/2023
Subject: Mr.
—————
Date: 23/12/2023
Subject: Mr.
—————
Date: 23/12/2023
Subject: Mr.
—————
