Servlet Questions and Answers
1. What is servlet?
|A servlet is a Java programming language class that is used to extend the capabilities of servers that host applications accessed by means of a request- response programming model. Before the servlet, CGI scripting language was used as server side programming language.|
2. How servlet is loaded?
|The servlet is loaded by: First request is made. Server starts up (auto-load). There is only a single instance which answers all requests concurrently. This saves memory and allows a Servlet to easily manage persistent data. Administrator manually loads.|
3. What are the new features added to Servlet 2.5?
|Following are the changes introduced in Servlet 2.5: A new dependency on J2SE 5.0 Support for annotations Loading the class Several web.xml conveniences A handful of removed restrictions Some edge case clarifications|
4. What are the advantages of jsp over servlet?
5. What is the difference between using getSession(true) and getSession(false) methods?
|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. getSession(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.|
6. How can we create deadlock condition on our servlet?
|one simple way to call doPost() method inside doGet() and doGet()method inside doPost() it will create deadlock situation for a servlet. This is rather simple servlet interview questions but yet tricky if you don’t think of it|
7. What is servlet interface?
|The central abstraction in the Servlet API is the Servlet interface. All servlets implement this interface, either directly or more commonly by extending a class that implements it.|
8. How is scripting disabled?
|Scripting is disabled by setting the scripting-invalid element of the deployment descriptor to true. It is a subelement of jsp-property-group. Its valid values are true and false.|
9. What is the output comment?
|The comment which is visible in the source of the response is called output comment.|
10. What is URL rewriting?
|URL rewriting is a method of session tracking in which some extra data is appended at the end of each URL. This extra data identifies the session. The server can associate this session identifier with the data it has stored about that session.|