according to The Java Servlet specification version 2.3 "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. .."
Filter is basically used to filter the request and responce. It is a certain API defined by the Filter, FilterChain, and FilterConfig interfaces in the javax.servlet package. With the help of this unwanted data refined by the filter and only required data only goes to server.