Home / Interview / Servlets :: General Questions

Interview :: Servlets

11) Can you call a jsp from the servlet?

Yes, one of the way is RequestDispatcher interface for example:

12) Difference between forward() method and sendRedirect() method ?
forward() methodsendRedirect() method
1) forward() sends the same request to another resource.1) sendRedirect() method sends new request always because it uses the URL bar of the browser.
2) forward() method works at server side.2) sendRedirect() method works at client side.
3) forward() method works within the server only.3) sendRedirect() method works within and outside the server.
13) What is difference between ServletConfig and ServletContext?

The container creates object of ServletConfig for each servlet whereas object of ServletContext is created for each web application.

14) What is Session Tracking?

Session simply means a particular interval of time.

Session Tracking is a way to maintain state of an user.Http protocol is a stateless protocol.Each time user requests to the server, server treats the request as the new request.So we need to maintain the state of an user to recognize to particular user.

15) What are Cookies?

A cookie is a small piece of information that is persisted between the multiple client requests. A cookie has a name, a single value, and optional attributes such as a comment, path and domain qualifiers, a maximum age, and a version number.

16) What is difference between Cookies and HttpSession?

Cookie works at client side whereas HttpSession works at server side.

17) What is filter?

A filter is an object that is invoked either at the preprocessing or postprocessing of a request. It is pluggable.

18) How can we perform any action at the time of deploying the project?

By the help of ServletContextListener interface.

19) What is the disadvantage of cookies?

It will not work if cookie is disabled from the browser.

20) How can we upload the file to the server using servlet?

One of the way is by MultipartRequest class provided by third party.