0

When we create Servlet object on JSP page or in Java class, How it works internally ? How it will effect on performance ?

Hardik Mishra
  • 14,779
  • 9
  • 61
  • 96
Parag
  • 145
  • 3
  • 13

2 Answers2

1

you should not call the servlet explicitly by the new keyword as we normally do.In the case of servlet, servlet container is responsible for instantiating the servlet.

For each servlet defined in the deployment descriptor of the Web application, the servlet container locates and loads a class of the type of the servlet. This can happen when the servlet engine itself is started, or later when a client request is actually delegated to the servlet.

There is only a single instance which answers all requests concurrently. This saves memory and allows a Servlet to easily manage persistent data.

When one create Servlet object on JSP page or in Java class,

You cannot expect to work it as a Servlet.

For More in details answer, Refer BalusC's answer here.

Community
  • 1
  • 1
Hardik Mishra
  • 14,779
  • 9
  • 61
  • 96
  • But I have already created servlet object explicitly on jsp and also on my java class. In this case how it will effect on performance of the application? – Parag Apr 23 '12 at 13:49
0

We can create an object of our servlet class. But because servlet operation depends on the servlet context, request, response, etc provided by the web container, there is nothing to be gained by creating one outside the container environment.

In one sentence - By doing so, we cannot expect to work as a servlet.

Taran
  • 27
  • 5