HOME      BLOG       FORUMS      CONTACT       ABOUT

JSP/Servlets interview questions – Part 4

81. When a session object gets added or removed to the session, which event will get notified ?
HttpSessionBindingListener will get notified When an object is added and/or removed from the session object, or when the session is invalidated, in which case the objects are first removed from the session, whether the session is invalidated manually or automatically (timeout).

82. What is URL Encoding and URL Decoding ?
URL encoding is the method of replacing all the spaces and other extra characters into their corresponding Hex Characters and Decoding is the process of converting all Hex Characters back to their normal form.

83. What is the difference between an applet and a servlet?
Servlets run inside a web server and applets run inside web browsers. Applets must have graphical user interfaces whereas servlets have no graphical user interfaces.

84. What are the different web servers available name few of them?
Tomcat, Java Web Server, JRun,

85. What is a Java Bean?
A Java Bean is a software component that has been designed to be reusable in a variety of different environments.

86. What are the different types of ServletEngines?
The different types of ServletEngines available are:- Standalone ServletEngine: This is a server that includes built-in support for servlets. Add-on ServletEngine: It is a plug-in to an existing server. It adds servlet support to a server that was not originally designed with servlets in mind.

87. What is a Session Id?
It is a unique id assigned by the server to the user when a user starts a session.

88. What is use of parseQueryString ?
It parses a query string and builds a Hashtable of key-value pairs, where the values are arrays of strings. The query string should have the form of a string packaged by the GET or POST method.

89. When init() and Destroy() will be called.
init() is called whenever the servlet is loaded for the first time into the web server. Destroy will be called whenever the servlet is removed from the web server.

90. What is the use of setComment and getComment methods in Cookies ?
setComment: If a web browser presents this cookie to a user, the cookie’s purpose will be described using this comment. This is not supported by version zero cookies.
getComment: Returns the comment describing the purpose of this cookie, or null if no such comment has been defined.

91. Why we are used setMaxAge() and getMaxAge() in Cookies ?
setMaxAge : Sets the maximum age of the cookie. The cookie will expire after that many seconds have passed. Negative values indicate the default behavior, and will be deleted when the browser closes.
getMaxAge : Returns the maximum specified age of the cookie. If none was specified, a negative value is returned, indicating the default behavior described with setMaxAge.

92. What is the use of setSecure() and getSecure() in Cookies ?
setSecure method indicates to the web browser that the cookie should only be sent using a secure protocol (https). getSecure method returns the value of the ‘secure’ flag.

93. How do you communicate between the servlets?
We can communicate between servlets by using RequestDespatcher interface and servlet chaining.

94. What is Servlet chaining?
Servlet chaining is a technique in which two or more servlets can cooperate in servicing a single request. In servlet chaining, one servlet’s output is the input of next servlet. This process continues until the last servlet is reached. Its output is then sent back to the client. We are achieving Servlet Chaining with the help of RequestDispatcher.

95. How will you communicate from an applet to servlet?
There are three ways to communicate from an applet to servlet and they are: HTTP Communication (Text-based and object-based) , Socket Communication and RMI Communication

96. Can we call a servlet with parameters in the URL?
Yes. You can call a servlet with parameters in the URL like ?param=value

97. How do servlets handle multiple simultaneous requests?
When a request comes in, the web server will start a new thread and the request is assigned to a thread, which calls a service method of the servlet.

98. Explain the directory structure of a web application?
The directory structure of a web application consists of two parts. A private directory called WEB-INF and a public resource directory which contains files server to public. WEB-INF folder consists of web.xml (the deployment descriptor), classes directory (where we keeps all our classes and servlets) and lib directory (where we keeps all our jar files). The public folder contains the static resources of the web application.

99. What is pre initialization of a servlet?
A container doesn’t initialize the servlets when it starts up. It initializes a servlet when it receives a request for that servlet first time. This is called lazy loading. The servlet specification defines the 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. The process of loading a servlet before any request comes in is called preloading or pre initializing a servlet.

100. What are the uses of ServletRequest?
The ServletRequest gives information such as the names of the parameters passed by the client, the protocol (scheme) being used by the client, and the names of the remote host that made the request and the server that received it. The input stream, ServletInputStream.

Share

Tags: , , ,


You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

AddThis Social Bookmark Button

Leave a Reply