Skip to main content

Posts

Showing posts from February 29, 2012

Servlet interview Questions & Answers

  Question: 1 What is a servlet filter? Ans: 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

Session Tracker Servlet

  JSP Page:index.jsp <%-- Document : index Created on : Feb 28, 2012, 3:32:07 PM Author : dell_pc --%> <%@page contentType=" text/html " pageEncoding=" UTF-8 "%> <!DOCTYPE HTML PUBLIC " -//W3C//DTD HTML 4.01 Transitional//EN " " http://www.w3.org/TR/html4/loose.dtd "> <html> <head> <meta http-equiv=" Content-Type " content=" text/html; charset=UTF-8 "> <title>JSP Page</title> </head> <body> <h1>Access Servlet by servlet's Name!</h1> <a href=" SessionTrackerServlet ">SessionTrackerServlet</a><br> <a href=" enumerationServlet ">enumerationServlet</a><br> </body> </html>   Servlet:SessionTrackerServlet.java package servlet; import java.io.IOException; import java.io.PrintWriter; import java.util.D

Session Management using servlet

Session management is the process of keeping track of the activities of a user across Web pages. Consider an example of an online shopping mall. The user can choose a product and add it to the shopping cart. When the user moves to a different page, the details in the shopping cart are still retained, so that the user can check the items in Messenger service in which the user name and the password are saved and displayed automatically as soon as you visit a web site. Some of the web sites track your email id and automatically start sending free subscription of their newsletters to the mail address. Session Management Techniques: HTTP is a stateless protocol and therefore cannot store the information about the user activities across Web pages. However, there are certain techniques that helps store the user information across Web pages using HTTP protocol. The techniques that you can use to maintain the session information are:     1)Hidden form field     2)URL rewriting     3)Coo