{
"iq":[{"id":"1",
"q":"What is a Servlet?",
"answer":"A servlet is a Java technology and it is managed by a container called servlet engine. It generates dynamic content and interacts with client through Request and Response. "
},
{"id":"2",
"q":"Why servlet is mostly used?",
"answer":"Servlets are mostly used because they are platform-independent Java classes and are compiled to platform-neutral byte code. Java byte code can be loaded dynamically into and run by java enabled web server. "
},
{"id":"3",
"q":"What is called servlet container?",
"answer":"A servlet container is a part of Web server that provides network services depends on request and response are sent, MIME based requests and responses. It contains and manages servlets through their life cycle."
},
{"id":"4",
"q":"What is a filter?",
"answer":"A filter is nothing but a piece of code which can be reusable that will be transforming the content of HTTP requests, response and header information. "
},
{"id":"5",
"q":"How can we refresh automatically when new data has entered the database? ",
"answer":"Refresh in Client side and Server Push can be performed to refresh automatically when new data is entered into the database."
},
{"id":"6",
"q":"What is called a session?",
"answer":"A session is an object which is used by a servlet and it is used to track user interaction with a web application across multiple HTTP requests. "
},
{"id":"7",
"q":"What is servlet mapping?",
"answer":"Servlet Mapping is an association mapping between servlet and a URL pattern. This is used to map servlets with the requests. "
},
{"id":"8",
"q":"Explain the life cycle methods of a Servlet.",
"answer":"The javax.servlet.Servlet interface defines the three methods known as life-cycle method.\n\npublic void init(ServletConfig config) throws ServletException\n\npublic void service( ServletRequest req, ServletResponse res) throws ServletException, IOException\n\npublic void destroy()\nFirst the servlet is constructed, then initialized wih the init() method.\nAny request from client are handled initially by the service() method before delegating to the doXxx() methods in the case of HttpServlet.\nThe servlet is removed from service, destroyed with the destroy() methid, then garbaged collected and finalized."
},
{"id":"9",
"q":"How can we create a Servelt?",
"answer":"A Servlet can be created by extending the httpServlet or GenericServlet classes."
},
{"id":"10",
"q":"Explain the common ways used for session tracking?",
"answer":"Cookies\nSSL sessions\nURL- rewriting"
},
{"id":"11",
"q":"Explain the difference between HttpServlet and GenericServlet?",
"answer":"A GenericServlet has a service() method to handle the requests. HttpServlet extends GenericServlet and adds support for doGet (), doPost () methods doPut (), doOptions (), doDelete (), doTrace () methods."
},
{"id":"12",
"q":"Explain the difference between ServletConfig and ServletContext?",
"answer":"ServletContext: It defines a set of methods that a servlet uses to communicate with its container.\n\nServletConfig: The object created after a servlet is instantiated and its default constructor is read. It is created to pass initialization information to the servlet."
},
{"id":"13",
"q":"Explain what is a session?",
"answer":"The session is an object used by a servlet to track a user’s interaction with a Web application across multiple HTTP requests. The session is stored on the server."
},
{"id":"14",
"q":"Explain the directory structure of a web application.",
"answer":"The directory structure of a web application consists of two parts.\nA private directory called WEB-INF\nA public resource directory which contains public resource folder.\n\nWEB-INF folder consists of\n1. web.xml\n2. classes directory\n3. lib directory"
},
{"id":"15",
"q":"Explain ServletContext. ",
"answer":"ServletContext interface is a window for a servlet to view it's environment.\nA servlet can use this interface to get information such as initialization parameters for the web applicationor servlet container's version.\nEvery web application has one and only one ServletContext and is accessible to all active resource of that application. "
},
{"id":"16",
"q":"What is preinitialization of a servlet?",
"answer":"A container doesnot initialize the servlets ass soon as it starts up,it initializes a servlet when it receives a request for that servlet first time.\nThis is called lazy loading. The servlet specification defines the\n<load-on-startup> element,which can be specified in the deployment descriptor to make the servlet container load and initialize the servlet as soon as it starts up.\n\nThe process of loading a servlet before any request comes in is called preloading or preinitializing a servlet. "
},
{"id":"17",
"q":"What is the difference between Difference between doGet() and doPost()?",
"answer":"A doGet() method is limited with 2k of data to be sent, and doPost() method doesn't have this limitation. A request string for doGet() looks like the following:\n\ndoPost() method call doesn't need a long text tail after a servlet name in a request. All parameters are stored in a request itself, not in a request string, and it's impossible to guess the data transmitted to a servlet only looking at a request string."
},
{"id":"18",
"q":"What is the difference between HttpServlet and GenericServlet?",
"answer":"A GenericServlet has a service() method aimed to handle requests. HttpServlet extends GenericServlet and adds support for doGet(), doPost(), doHead() methods (HTTP 1.0) plus doPut(), doOptions(), doDelete(), doTrace() methods (HTTP 1.1).Both these classes are abstract. "
},
{"id":"19",
"q":"What is the difference between ServletContext and ServletConfig?",
"answer":"ServletContext: Defines a set of methods that a servlet uses to communicate with its servlet container, for example, to get the MIME type of a file, dispatch requests, or write to a log file.The ServletContext object is contained within the ServletConfig object, which the Web server provides the servlet when the servlet is initialized\n\nServletConfig: The object created after a servlet is instantiated and its default constructor is read. It is created to pass initialization information to the servlet."
},
{"id":"20",
"q":"What are the parameters for service method?",
"answer":"ServletRequest and ServletResponse. "
},
{"id":"21",
"q":"Can we write a constructor for servlet ?",
"answer":"Yes. But the container will always call the default constructor only. If default constructor is not present, the container will throw an exception. "
},
{"id":"22",
"q":"Can we use the constructor, instead of init(), to initialize servlet? ",
"answer":"Yes. But you will not get the servlet specific things from constructor.\n\nThe original reason for init() was that old versions of Java couldn’t dynamically invoke constructors with arguments, so there was no way to give the constructor a ServletConfig.\nThat no longer applies, but servlet containers still will only call your no-arg constructor. So you won’t have access to a ServletConfig or ServletContext. "
},
{"id":"23",
"q":"What is servlet mapping?",
"answer":"The servlet mapping defines an association between a URL pattern and a servlet. The mapping is used to map requests to Servlets."
},{"id":"24",
"q":"How Can you include other Resources in the Response? ",
"answer":"Using include method of a RequestDispatcher object.\nIncluded WebComponent (Servlet / Jsp) cannot set headers or call any method (for example, setCookie) that affects the headers of the response.\n\nExample : RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(“/banner”);\nif (dispatcher != null)\ndispatcher.include(request, response);\n}"
},{"id":"25",
"q":"How Can You invoke other web resources (or other servlet / jsp ) ?",
"answer":"Servelt can invoke other Web resources in two ways: indirect and direct.\n\nIndirect Way : Servlet will return the resultant HTML to the browser which will point to another Servlet (Web resource)\n\nDirect Way : We can call another Web resource (Servelt / Jsp) from Servelt program itself, by using RequestDispatcher object.\nYou can get this object using getRequestDispatcher(“URL”) method. You can get this object from either a request or a Context.\n\nExample :\nRequestDispatcher dispatcher = request.getRequestDispatcher(\"/jspsample.jsp\");\nif (dispatcher != null)\ndispatcher.forward(request, response);\n }"
},{"id":"26",
"q":"Which protocol will be used by browser and servlet to communicate ?",
"answer":"HTTP"
},{"id":"27",
"q":"Which code line must be set before any of the lines that use the PrintWriter?",
"answer":"setContentType() method must be set."
},{"id":"28",
"q":"What is the difference between using getSession(true) and getSession(false) methods? ",
"answer":"getSession(true) – This method will check whether already a session is existing for the user. If a session is existing, it will return that session object, Otherwise it will create new session object and return taht object.\ngetSession(false) – This method will check existence of session. If session exists, then it returns the reference of that session object, if not, this methods will return null."
},{"id":"29",
"q":"Is there any way to generate PDF’S dynamically in servlets? ",
"answer":"We need to use iText. A open source library for java.\nPlease refer sourceforge site for sample servlet examples."
},{"id":"30",
"q":"What is a servlet context? ",
"answer":"Servlet context contains servlet view of Web application in which servlet will be running. By using the context,\n\nLog events\nObtain URL references to resources\nSet and Store attributes"
},{"id":"31",
"q":"Which interface should be implemented by all servlets? ",
"answer":"Servlet interface should be implemented by all servlets."
},{"id":"32",
"q":"What is life cycle of Servlet?",
"answer":"Loaded\nInitialized\nDestroy\nUnloaded "
},{"id":"33",
"q":"What is the difference between Servlet Request and Servlet Context when calling a Request Dispatcher?",
"answer":"Relative URL can be called when Servlet Request is used and Relative URL is not used when using Servlet Context. "
},{"id":"34",
"q":"When servlet is loaded?",
"answer":"A servlet can be loaded when:\nFirst request is made\nAuto loading and Server starts up\nThere is a single instance that answers all requests concurrently which saves memory\nAdministrator manually loads. "
},{"id":"35",
"q":"When Servlet is unloaded?",
"answer":"A servlet is unloaded when:\nServer shuts down\nAdministrator manually unloads"
},{"id":"36",
"q":"What are the supporting protocol by HttpServlet ?",
"answer":"HttpServlet supports only HTTP and HTTPS protocol."
},{"id":"37",
"q":"What is called Session Tracking?",
"answer":"Session tracking is used to maintain a state on the series of requests from the same user for a given period of time. "
},{"id":"38",
"q":"What are the types of Session Tracking ?",
"answer":"There are following types of session tracking:\n\nURL rewriting\nHidden Form Fields\nCookies\nSecure Socket Layer (SSL)"
},{"id":"39",
"q":"What are the advantages of cookies? ",
"answer":"Cookies are used to store long term information that can be maintained without server interaction. Small and Medium size data are kept in a queue."
},{"id":"40",
"q":"What is servlet lazy loading? ",
"answer":"A servlet container which does not initialize at the start up, this is known as servlet lazy loading."
},{"id":"41",
"q":"What is Servlet Chaining? ",
"answer":"Chaining is one of the methods where out of one servlet is given to the second servlet. This chaining can happen for any number of servlets."
},{"id":"42",
"q":"What is called Scriptlet? ",
"answer":"A scriptlet contains any language statements, variables, expressions that can be valid in the page scripting language. Scriptlet is a part of generated servlet service method."
},{"id":"43",
"q":"What is Pure Servlet?",
"answer":"Pure servlet is servlet which is used to create java objects that can be implemented from javax.servlet.Servlet interface."
},{"id":"44",
"q":"What is the difference between Servlets and applets?",
"answer":"Servlets are used for server side config and it keeps on server. But, Applets are used for client side coding and it runs on client browsers."
},{"id":"45",
"q":"What is Generic Servlet class? ",
"answer":"Generic servlet is the super class of all servlets. This class is extended by all other classes and it is protocol independent."
},{"id":"46",
"q":"How to get the current HttpSession object?",
"answer":"GetSession method is used to get the current HttpSession object on HttpservletRequest. "
},{"id":"47",
"q":"What is Servlet Invoker?",
"answer":"Servlet Invoker allows web application to dynamically register new servlet definitions with the servlet tag in the /WEB-INF/web.xml."
},{"id":"48",
"q":"What are all the protocols supported by HttpServlet?",
"answer":"HttpServlet supports HTTP and HTTPS protocol. "
},{"id":"49",
"q":"What exception should be thrown when servlet is not properly initialized? ",
"answer":"Servlet exception or an Unavailable exception is thrown when it is not properly initialized. "
},{"id":"50",
"q":" What is the default HTTP method in the servlet? ",
"answer":"Default method is GET method for HTTPservlet."
}
]
}
"iq":[{"id":"1",
"q":"What is a Servlet?",
"answer":"A servlet is a Java technology and it is managed by a container called servlet engine. It generates dynamic content and interacts with client through Request and Response. "
},
{"id":"2",
"q":"Why servlet is mostly used?",
"answer":"Servlets are mostly used because they are platform-independent Java classes and are compiled to platform-neutral byte code. Java byte code can be loaded dynamically into and run by java enabled web server. "
},
{"id":"3",
"q":"What is called servlet container?",
"answer":"A servlet container is a part of Web server that provides network services depends on request and response are sent, MIME based requests and responses. It contains and manages servlets through their life cycle."
},
{"id":"4",
"q":"What is a filter?",
"answer":"A filter is nothing but a piece of code which can be reusable that will be transforming the content of HTTP requests, response and header information. "
},
{"id":"5",
"q":"How can we refresh automatically when new data has entered the database? ",
"answer":"Refresh in Client side and Server Push can be performed to refresh automatically when new data is entered into the database."
},
{"id":"6",
"q":"What is called a session?",
"answer":"A session is an object which is used by a servlet and it is used to track user interaction with a web application across multiple HTTP requests. "
},
{"id":"7",
"q":"What is servlet mapping?",
"answer":"Servlet Mapping is an association mapping between servlet and a URL pattern. This is used to map servlets with the requests. "
},
{"id":"8",
"q":"Explain the life cycle methods of a Servlet.",
"answer":"The javax.servlet.Servlet interface defines the three methods known as life-cycle method.\n\npublic void init(ServletConfig config) throws ServletException\n\npublic void service( ServletRequest req, ServletResponse res) throws ServletException, IOException\n\npublic void destroy()\nFirst the servlet is constructed, then initialized wih the init() method.\nAny request from client are handled initially by the service() method before delegating to the doXxx() methods in the case of HttpServlet.\nThe servlet is removed from service, destroyed with the destroy() methid, then garbaged collected and finalized."
},
{"id":"9",
"q":"How can we create a Servelt?",
"answer":"A Servlet can be created by extending the httpServlet or GenericServlet classes."
},
{"id":"10",
"q":"Explain the common ways used for session tracking?",
"answer":"Cookies\nSSL sessions\nURL- rewriting"
},
{"id":"11",
"q":"Explain the difference between HttpServlet and GenericServlet?",
"answer":"A GenericServlet has a service() method to handle the requests. HttpServlet extends GenericServlet and adds support for doGet (), doPost () methods doPut (), doOptions (), doDelete (), doTrace () methods."
},
{"id":"12",
"q":"Explain the difference between ServletConfig and ServletContext?",
"answer":"ServletContext: It defines a set of methods that a servlet uses to communicate with its container.\n\nServletConfig: The object created after a servlet is instantiated and its default constructor is read. It is created to pass initialization information to the servlet."
},
{"id":"13",
"q":"Explain what is a session?",
"answer":"The session is an object used by a servlet to track a user’s interaction with a Web application across multiple HTTP requests. The session is stored on the server."
},
{"id":"14",
"q":"Explain the directory structure of a web application.",
"answer":"The directory structure of a web application consists of two parts.\nA private directory called WEB-INF\nA public resource directory which contains public resource folder.\n\nWEB-INF folder consists of\n1. web.xml\n2. classes directory\n3. lib directory"
},
{"id":"15",
"q":"Explain ServletContext. ",
"answer":"ServletContext interface is a window for a servlet to view it's environment.\nA servlet can use this interface to get information such as initialization parameters for the web applicationor servlet container's version.\nEvery web application has one and only one ServletContext and is accessible to all active resource of that application. "
},
{"id":"16",
"q":"What is preinitialization of a servlet?",
"answer":"A container doesnot initialize the servlets ass soon as it starts up,it initializes a servlet when it receives a request for that servlet first time.\nThis is called lazy loading. The servlet specification defines the\n<load-on-startup> element,which can be specified in the deployment descriptor to make the servlet container load and initialize the servlet as soon as it starts up.\n\nThe process of loading a servlet before any request comes in is called preloading or preinitializing a servlet. "
},
{"id":"17",
"q":"What is the difference between Difference between doGet() and doPost()?",
"answer":"A doGet() method is limited with 2k of data to be sent, and doPost() method doesn't have this limitation. A request string for doGet() looks like the following:\n\ndoPost() method call doesn't need a long text tail after a servlet name in a request. All parameters are stored in a request itself, not in a request string, and it's impossible to guess the data transmitted to a servlet only looking at a request string."
},
{"id":"18",
"q":"What is the difference between HttpServlet and GenericServlet?",
"answer":"A GenericServlet has a service() method aimed to handle requests. HttpServlet extends GenericServlet and adds support for doGet(), doPost(), doHead() methods (HTTP 1.0) plus doPut(), doOptions(), doDelete(), doTrace() methods (HTTP 1.1).Both these classes are abstract. "
},
{"id":"19",
"q":"What is the difference between ServletContext and ServletConfig?",
"answer":"ServletContext: Defines a set of methods that a servlet uses to communicate with its servlet container, for example, to get the MIME type of a file, dispatch requests, or write to a log file.The ServletContext object is contained within the ServletConfig object, which the Web server provides the servlet when the servlet is initialized\n\nServletConfig: The object created after a servlet is instantiated and its default constructor is read. It is created to pass initialization information to the servlet."
},
{"id":"20",
"q":"What are the parameters for service method?",
"answer":"ServletRequest and ServletResponse. "
},
{"id":"21",
"q":"Can we write a constructor for servlet ?",
"answer":"Yes. But the container will always call the default constructor only. If default constructor is not present, the container will throw an exception. "
},
{"id":"22",
"q":"Can we use the constructor, instead of init(), to initialize servlet? ",
"answer":"Yes. But you will not get the servlet specific things from constructor.\n\nThe original reason for init() was that old versions of Java couldn’t dynamically invoke constructors with arguments, so there was no way to give the constructor a ServletConfig.\nThat no longer applies, but servlet containers still will only call your no-arg constructor. So you won’t have access to a ServletConfig or ServletContext. "
},
{"id":"23",
"q":"What is servlet mapping?",
"answer":"The servlet mapping defines an association between a URL pattern and a servlet. The mapping is used to map requests to Servlets."
},{"id":"24",
"q":"How Can you include other Resources in the Response? ",
"answer":"Using include method of a RequestDispatcher object.\nIncluded WebComponent (Servlet / Jsp) cannot set headers or call any method (for example, setCookie) that affects the headers of the response.\n\nExample : RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(“/banner”);\nif (dispatcher != null)\ndispatcher.include(request, response);\n}"
},{"id":"25",
"q":"How Can You invoke other web resources (or other servlet / jsp ) ?",
"answer":"Servelt can invoke other Web resources in two ways: indirect and direct.\n\nIndirect Way : Servlet will return the resultant HTML to the browser which will point to another Servlet (Web resource)\n\nDirect Way : We can call another Web resource (Servelt / Jsp) from Servelt program itself, by using RequestDispatcher object.\nYou can get this object using getRequestDispatcher(“URL”) method. You can get this object from either a request or a Context.\n\nExample :\nRequestDispatcher dispatcher = request.getRequestDispatcher(\"/jspsample.jsp\");\nif (dispatcher != null)\ndispatcher.forward(request, response);\n }"
},{"id":"26",
"q":"Which protocol will be used by browser and servlet to communicate ?",
"answer":"HTTP"
},{"id":"27",
"q":"Which code line must be set before any of the lines that use the PrintWriter?",
"answer":"setContentType() method must be set."
},{"id":"28",
"q":"What is the difference between using getSession(true) and getSession(false) methods? ",
"answer":"getSession(true) – This method will check whether already a session is existing for the user. If a session is existing, it will return that session object, Otherwise it will create new session object and return taht object.\ngetSession(false) – This method will check existence of session. If session exists, then it returns the reference of that session object, if not, this methods will return null."
},{"id":"29",
"q":"Is there any way to generate PDF’S dynamically in servlets? ",
"answer":"We need to use iText. A open source library for java.\nPlease refer sourceforge site for sample servlet examples."
},{"id":"30",
"q":"What is a servlet context? ",
"answer":"Servlet context contains servlet view of Web application in which servlet will be running. By using the context,\n\nLog events\nObtain URL references to resources\nSet and Store attributes"
},{"id":"31",
"q":"Which interface should be implemented by all servlets? ",
"answer":"Servlet interface should be implemented by all servlets."
},{"id":"32",
"q":"What is life cycle of Servlet?",
"answer":"Loaded\nInitialized\nDestroy\nUnloaded "
},{"id":"33",
"q":"What is the difference between Servlet Request and Servlet Context when calling a Request Dispatcher?",
"answer":"Relative URL can be called when Servlet Request is used and Relative URL is not used when using Servlet Context. "
},{"id":"34",
"q":"When servlet is loaded?",
"answer":"A servlet can be loaded when:\nFirst request is made\nAuto loading and Server starts up\nThere is a single instance that answers all requests concurrently which saves memory\nAdministrator manually loads. "
},{"id":"35",
"q":"When Servlet is unloaded?",
"answer":"A servlet is unloaded when:\nServer shuts down\nAdministrator manually unloads"
},{"id":"36",
"q":"What are the supporting protocol by HttpServlet ?",
"answer":"HttpServlet supports only HTTP and HTTPS protocol."
},{"id":"37",
"q":"What is called Session Tracking?",
"answer":"Session tracking is used to maintain a state on the series of requests from the same user for a given period of time. "
},{"id":"38",
"q":"What are the types of Session Tracking ?",
"answer":"There are following types of session tracking:\n\nURL rewriting\nHidden Form Fields\nCookies\nSecure Socket Layer (SSL)"
},{"id":"39",
"q":"What are the advantages of cookies? ",
"answer":"Cookies are used to store long term information that can be maintained without server interaction. Small and Medium size data are kept in a queue."
},{"id":"40",
"q":"What is servlet lazy loading? ",
"answer":"A servlet container which does not initialize at the start up, this is known as servlet lazy loading."
},{"id":"41",
"q":"What is Servlet Chaining? ",
"answer":"Chaining is one of the methods where out of one servlet is given to the second servlet. This chaining can happen for any number of servlets."
},{"id":"42",
"q":"What is called Scriptlet? ",
"answer":"A scriptlet contains any language statements, variables, expressions that can be valid in the page scripting language. Scriptlet is a part of generated servlet service method."
},{"id":"43",
"q":"What is Pure Servlet?",
"answer":"Pure servlet is servlet which is used to create java objects that can be implemented from javax.servlet.Servlet interface."
},{"id":"44",
"q":"What is the difference between Servlets and applets?",
"answer":"Servlets are used for server side config and it keeps on server. But, Applets are used for client side coding and it runs on client browsers."
},{"id":"45",
"q":"What is Generic Servlet class? ",
"answer":"Generic servlet is the super class of all servlets. This class is extended by all other classes and it is protocol independent."
},{"id":"46",
"q":"How to get the current HttpSession object?",
"answer":"GetSession method is used to get the current HttpSession object on HttpservletRequest. "
},{"id":"47",
"q":"What is Servlet Invoker?",
"answer":"Servlet Invoker allows web application to dynamically register new servlet definitions with the servlet tag in the /WEB-INF/web.xml."
},{"id":"48",
"q":"What are all the protocols supported by HttpServlet?",
"answer":"HttpServlet supports HTTP and HTTPS protocol. "
},{"id":"49",
"q":"What exception should be thrown when servlet is not properly initialized? ",
"answer":"Servlet exception or an Unavailable exception is thrown when it is not properly initialized. "
},{"id":"50",
"q":" What is the default HTTP method in the servlet? ",
"answer":"Default method is GET method for HTTPservlet."
}
]
}