How do servlets work?

I write pairs of servlet programs, but I don’t think I fully understand how the servlet works. So, here are a couple of questions that I have:

All the code that I wrote about the servlet runs only on Netbeans with apache tomcat. When I run my html file that makes a request for a servlet, it usually gives an error saying that it cannot find the servlet, then I need to redistribute the servlet, then everything will work fine. It seems my servlet timeout after a while or something like that.

Does the servlet work all the time? The servlet has init () and destroy (), so I assume that it will not work all the time. So when does it start and when does it end? Does this start when there is a request from the client and does the wait time end? And as I fixed my problem, that I have to constantly reinstall the servlet. Many thanks.

+3
source share
4 answers

(.. , Tomcat, ). . , Netbeans, WAR Tomcat , .

, destroy , , .

, . , , .

+4

, -, . , webapp , web.xml Servlet. , .

" " , "404 ". , URL- url-pattern. .

Servlet, webapp (, ), init(), Map<Url-Pattern, Servlet>. init() Servlet, . , web.xml ( Java EE 6, @WebServlet).

, , URL url-pattern Servlet, () service(). HttpServlet , HttpServletRequest#getMethod(). (doGet(), doPost() ..) Servlet, .

, webapp ( , ), destroy() Servlet, . destroy() Servlet, .

+2

"" . , , web.xml, service() . , ( , ). , .

, , , . , , , . , - , .

+1

- , init() destroy

init() , serlvet ( - tomcat)

destroy() ,

dopost() doGet() ( HTTP-)

0

Source: https://habr.com/ru/post/1728361/


All Articles