Java Servlets Question and Answers

29. What are methods of HttpServlet?
 
    Java Servlets have a number of advantages over CGI and other API's. They are Platform Independence: Java Servlets are 100% pure Java, so it is platform independence. It can run on any Servlet enabled web server.
  • Performance: Due to interpreted nature of java, programs written in java are slow. But the java servlets run very fast. These are due to the way servlets run on the web server. For any program initialization takes significant amount of time. But in case of servlets, initialization takes place the very first time it receives a request and remains in memory till times out or secure shut downs. After the servlet is loaded, to handle a new request it simply creates a new thread and runs service method of servlet. In comparison to traditional CGI scripts which creates a new process to serve the request. This intuitive method of servlets could be used to develop high speed data driven websites.
  • Extensibility: Java Servlets are developed in java which is robust, well designed and object oriented language which can be extended or polymorhed into new objects. So the java servlets takes all these advantages and can be extended from the existing class that provide the ideal solutions. Safety: Java provides very good safety features like memory management, exception handling etc. Servlets inherits all these features and emerged as a very powerful web server extension.
  • Secure: Servlets are server side components, so it inherits the security provided by the web server. Servlets are also benefited with Java Security Manager.
 
Your Name Your Email-ID
Your Answer
30. What is meant by Pre-initialization of Servlet?
 
  • When servlet container is loaded, all the servlets defined in the web.xml file are not initialized by default. But the container receives the request it loads the servlet. But in some cases if you want your servlet to be initialized when context is loaded, you have to use a concept called pre-initialization of servlet. In case of Pre-initialization, the servlet is loaded.
 
Your Name Your Email-ID
Your Answer
31. How you can destroy the Session in Servlet?
  You can call invalidate() method on the session object to destroy the session. E.g. session.invalidate().
 
Your Name Your Email-ID
Your Answer
32. What is an HTTPSession Class?
 
  • HTTPSession Class provides a way to identify a user across multiple requests.
  • The servlet container uses HTTPSession interface to create a session between an HTTP client and an HTTP server.
  • The session lives only for a specified time period, across more than one connection or page request from the user.
 
Your Name Your Email-ID
Your Answer
1234567891011 Page 8 of 11