Java – how does a servlet work?

I've written several servlet programs, but I don't think I fully understand how servlets work So this is a husband and wife problem. I have:

All the code I wrote about servlet can only run on NetBeans, followed by Apache Tomcat When I run an HTML file that makes a request to a servlet, it usually gives an error that it can't find the servlet, and then I have to redeploy the servlet and everything works normally It looks like my servlet timed out after a while

Is the servlet always running? Servlet has init () and destroy (), so I guess it won't run all the time So when does it start and end? Does it start when there is a request from the client and end at the timeout? How do I solve the problem that I have to constantly redeploy servlets thank you very much.

Solution

Under normal circumstances, servlets are destroyed only when they are closed (that is, when an application container, such as tomcat, is closed) Otherwise, it remains in memory for the duration of the application I can't tell what happened to your NetBeans settings, but try deploying the war file to a separate Tomcat installation and see if the problem disappears

Another time the application container calls destroy on the servlet is out of memory, but this is not common

With regard to requests, servlets are designed to handle many requests It is said that servlets are application scoped and requests have their own scope

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
分享
二维码
< <上一篇
下一篇>>