tags:

views:

72

answers:

1

Hi I like to know is there any other way servlet instance get created. One way is when client makes a first request to the servlet.

Thanks

+6  A: 

You can specify servlet creation/running on startup of the container.

<servlet>
 <servlet-name>TestServlet</servlet-name>
 <servlet-class>TestServlet</servlet-class>
 <load-on-startup>1</load-on-startup>
</servlet>

specifies a startup order. The above specifies that TestServlet will start on container startup, and be the first (hence 1).

I often prefer servlets starting during container startup. It allows them to perform any time-consuming initialisation prior to client interaction.

EDIT: As Skaffman pointed out below, 0 means start on first request.

Brian Agnew
And a zero value means startup on first request, not just the ordering
skaffman
@Skaffman - good point. Yes.
Brian Agnew