Servlets Interview Questions and Answers For Freshers Part-5
// Create a session object if it is already not created.
HttpSession session = request.getSession();
42.How to delete a session in servlet?
When you are done with a user’s session data, you have several options:
Remove a particular attribute: You can call public void removeAttribute(String name) method to delete the value associated with a particular key.
Delete the whole session: You can call public void invalidate() method to discard an entire session. Setting Session timeout: You can call public void setMaxInactiveInterval(int interval) method to set the timeout for a session individually.
Log the user out: The servers that support servlets 2.4, you can call logout to log the client out of the Web server and invalidate all sessions belonging to all the users.
43.How to update an attribute in session in servlet?
setAttribute(String name, Object value) of HTTPSession object binds an object to this session, using the name specified and can be used to update an attribute in session.
44.How to set session timeout in servlet?
setMaxInactiveInterval(int interval) of HTTPSession object specifies the time, in seconds, between client requests before the servlet container will invalidate this session.
45.How to set auto page refresh in servlet?
The simplest way of refreshing a web page is using method setIntHeader() of response object.
46.What is internalization?
This means enabling a web site to provide different versions of content translated into the visitor’s language or nationality.
47.What is localization?
This means adding resources to a web site to adapt it to a particular geographical or cultural region for example Hindi translation to a web site.
48.What is locale?
This is a particular cultural or geographical region. It is usually referred to as a language symbol followed by a country symbol which is separated by an underscore. For example “en_US” represents english locale for US.
49.How to detect locale in Servlets?
Following is the method of request object which returns Locale object.
50.How to get country name in Servlets?
Following method returns a name for the locale’s country that is appropriate for display to the user.