Posts

Showing posts from April, 2010

Understanding Observer Designing Pattern by Example

Image
  “The Observer pattern define a one to many dependency between objects so that when one object changes state, all of its dependents are notified and updated automatically.” With the observer pattern, the source is the object that contain the state and control it. The Observer on the other hand use the state, even if they don’t own it. The observer pattern provides an object design where the subject and observer are loosely coupled. Here is the Class Diagram explaining Benefit of loosely coupling The only thing the subject knows about an Observer is that it implements a certain interface We can add new Observer at any time We never need to modify subject to add more observer. We can use subject or observer independently of each other. Change in either observer or Source will not affect the other. Here is an example : This example explains Observer pattern, here source generates random characters and observer, Java Swing component listen this eve...

First Hand on Servlet Filter

Image
Servlet Filter is introduced in Servlet 2.3 specifications. It is explained as “A filter dynamically intercepts requests and responses to transform or use the information contained in the requests or responses.” Servlet Filter performs two main tasks transform the request modify the response They are preprocessors of the request before it reaches a servlet, and/or postprocessors of the response leaving a servlet. You can configure a filter to act on a servlet or group of servlets. Zero or more filters can filter one or more servlets. Here is the short tutorial to explain developing a simple filter for the Servlet. I have used NetBean for ease of development . 1. Create a Java Web App 2. Create sample Servlet   1: import java.io.IOException; 2: import java.io.PrintWriter; 3: import javax.servlet.ServletException; 4: import javax.servlet.annotation.WebInitParam; 5: import javax.servlet.annotation.WebServlet; 6: import javax.servlet.http.HttpSe...