How to improve Servlet performance

Use the servlet init() method to cache static data, and release them in the destroy() method. Use StringBuffer rather than using + operator when you concatenate multiple strings. Use the print() method rather than the println() method. Use a ServletOutputStream rather than a PrintWriter to send binary data. Initialize the PrintWriter with the optimal size [...]

Can servlet have a constructor ?

Servlet can have a constructor. But you never call the constructor for the servlet / instantiate them , because the container handles it. So you are better of doing initialization / one-time setup code in the init method of the servlet. Also, the container passes the ServletConfig object to the servlet only when it calls the init [...]

39. What is the differences between Http Servlet and generic Servlet

HttpServlet Provides an abstract class to be subclassed to create an HTTP servlet suitable for a Web site. A subclass of HttpServlet must override at least one method, usually one of these: doGet, if the servlet supports HTTP GET requests doPost, for HTTP POST requests doPut, for HTTP PUT requests doDelete, for HTTP DELETE requests [...]

38. Servlets 20 mins drill and Quiz.

What is the servlet? Servlet is a script, which resides and executes on server side, to create dynamic HTML. In servlet programming we will use java language. A servlet can handle multiple requests concurrently What’s the difference between servlets and applets? Servlets executes on Servers. Applets executes on browser. Unlike applets, however, servlets have no [...]

37. What is servlet lazy loading.

A container doesnot initialize the servlets ass soon as it starts up, it initializes a servlet when it receives a request for that servlet first time. This is called lazy loading. The servlet specification defines the <load-on-startup> element, which can be specified in the deployment descriptor to make the servlet container load and initialize the [...]

32. What is the difference between ServletContext and ServletConfig

public interface ServletContext Defines a set of methods that a servlet uses to communicate with its servlet container, for example, to get the MIME type of a file, dispatch requests, or write to a log file. There is one context per “web application” per Java Virtual Machine. The ServletContext object is contained within the ServletConfig [...]

31. Explain Servlet Life Cycle.

Servlets are normal Java classes which are created when needed and destroyed when not needed. Since Servlets run within a Servlet Container, creation and destruction of Servlets is the duty of Servlet Container and not yours. Implementing the init() and destory() methods of Servlet interface allows you to be told by the Servlet Container that [...]

Follow

Get every new post delivered to your Inbox.