Java – how to initialize a servlet when the server starts

I wrote a simple servlet with init () and doget (), dopost () methods I have a request, I have an API, I need to call the server to start

Is it possible to do so I try to use the init method and use it on the web XML, but I still can't

Please tell me if I missed anything

thank you

Solution

Do you set the load on startup property to a positive value?

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

Alternatively, you may want to use servletcontextlistener for initialization when the container starts This is a "de facto" standard for callback to perform some initialization when the servlet container is online. For example, we use it to read some XML files and fill the cache

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>