How to initialize a servlet at server startup

I wrote a simple servlet init()and doGet(), doPost(). I have a requirement that I have an API that I need to call the server to start.

Is it possible to do this. I tried using the init method and set the default values ​​in web.xml, but I still can not do this.

Tell me if something is missing.

thank

+5
source share
2 answers

Have you set the load on on startup attribute?

<servlet id="servlet1">
<load-on-startup>2</load-on-startup>
</servlet>

ServletContextListener . - , , , . XML .

+15

listener . ,... web.xml. . java API.

<web-app>
<listener>
    <listener-class>MyServlet</listener-class>
</listener>

</web-app>

, .

0

All Articles