java4all@1986 java. Powered by Blogger.

>> Wednesday, June 15, 2011

Q).How can we will implement singleton pattern in servlets?
A).Singleton is a useful Design Pattern for allowing only one instance of your class.you can implement singleton pattern in servlets by using using Servlet init() and <load-on-startup> in the deployment descriptor.

Q.)What is servlet Exception?
A.)ServletException is a subclass of the Exception. It defines a general exception a servlet can throw when it encounters difficulty.
ServletException class define only one method getRootCause() that returns the exception that caused this servlet exception.
It inherit the other methods like fillInStackTrace, getLocalizedMessage, getMessage, printStackTrace, printStackTrace, printStackTrace, toString etc from the Throwable class.
Packages that use ServletException :
  * javax.servlet
  * javax.servlet.http









                           
Q).What is a Servlet Filter?
A).   

A filter dynamically 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 provide the ability to encapsulate recurring tasks in reusable units and can be used to transform the response from a servlet or a JSP page.
Filters can perform many different types of functions:
  * Authentication
  * Logging and auditing
  * Data compression
  * Localization

The filter API is defined by the Filter, FilterChain, and FilterConfig interfaces in the javax.servlet package. You define a filter by implementing the Filter interface. A filter chain, passed to a filter by the container, provides a mechanism for invoking a series of filters. Filters must be configured in the deployment descriptor :

<!--Servlet Filter that handles site authorization.-->
<filter>
     <filter-name>AuthorizationFilter</filter-name>
     <filter-class>examples.AuthorizationFilter</filter-class>
     <description>This Filter authorizes user access to application components based upon request URI.</description>
     <init-param>
        <param-name>error_page</param-name>
        <param-value>../../error.jsp</param-value>
     </init-param>
</filter>

<filter-mapping>
     <filter-name>AuthorizationFilter</filter-name>
     <url-pattern>/restricted/*</url-pattern>
</filter-mapping>

 

0 comments:

Post a Comment

FaceBook Login

HTML/JAVASCRIPT

HTML/JAVASCRIPT

HTML/JAVASCRIPT

HTML/JAVASCRIPT

Total Pageviews

STATCOUNTER

  © Blogger template Simple n' Sweet by Ourblogtemplates.com 2009

Back to TOP