Tuesday, January 15, 2008

servlets frequently asked questions

Q. what is servlet?
a) Servlet is a program running at server side and acting as middle layer between webbrowser or other HTTPclients and database or applications on HTTPServer.

Q. Advantages of servlets over CGI?
a) 1. efficient 2. easier to use 3. more powerful 4. more portable 5. safer 6. cheaper.
efficient:
1. in cgi new process is started for every request. for servlets new thread is started for every
request
2. In CGI if there are n requests then program is loaded n times. In servlets for n threads one
program will be loaded.
3. When a CGI finiseshes handling a request the program terminates persistency of data is
difficult.
Servlets will remain after completion of response so persistency is easy.
powerful:
1. CGI can't talk with server. Servlets can directly talk with server.
2. Multiple servlets can share data so implementation of connection pooling, resource sharing is easy
3. Servlets can also maintain information from request to request by using session tracking.
Portable:
1. Servlets can run on any server like IIS.

Q. Servlet architecture?
Q. What is the difference between servlet and jsp?
Q. When we choose servlet?
Q. When we choose JSP?
Q. What package we use for servlets?

Q. Life cycle of servlet?
a) 1. init() 2. service() 3. destroy()

Q. Can we call destroy method explicitly in servlet?
Q. is javax.servlet.Servlet interface or class?
Q. what methods we should override if we implement javax.servlet.Servlet?
Q. Is javax.servlet.GenericServlet abstract class?
Q. what methods we should override if we implement javax.servlet.GenericServlet?
Q. what is httpServlet?

Q. By default is servlet thread safe?
a) no

Q. How to make a servlet thread safe?
a) By extending SingleThreadModel.

Q. Difference between doGet and doPost?
Q. what is ServletConfig?
Q. Difference between ServletConfig and ServletContext?

Q. How to get initial parameters in a servlet?
Q. How to initialize servlet?
Q. Why init method?

Q. different types of session tracking techniques?
a) 1. URLrewriting 2. hiddenform fields 3. Cookies 4. Sessions

Q. what is urlrewriting?
Q. Difference between urlrewriting and hidden form fields?
Q. what is cookie?
Q. what is a httpsession?

Q. Difference between cookie and session?
a) cookie - cookie is a small text file. Cookie is not secure. Cookie will work at client side.
Session - Session can hold large data. Session is secure. session will work at server side.

Q. Difference between URLrewriting and Cookie?
Q. How to find cookie is enable or disabled at server side?
Q. what is servletContext?
Q. How to forward from one servlet to another servlet?
Q. Two types for getting RequestDispatcher?
Q. What is the difference on getting RequestDispatcher on request to servletContext?
Q. Difference between include and forward?
Q. Difference between sendRedirect and forward?
Q. difference between version1.o to version2.0?
Q. difference between version2.0 to version2.1?
Q. what are the advantages over CGI?

Q. What is deployment descriptor?
a) Web.xml , it describes our application structure. It tells how many servlets in our application and what are the url patterns and some other details regarding our application.

Q. How to specify initial parameters in web.xml?
Q. How can you store session data in servlet?

Q. How to remove session?
a) session.invalidate();

Q. DataBase is down how to save that data by using servlets?

No comments: