简体   繁体   中英

After changing the path to '/', why does apache tomcat call the servlet's doGet method on start/restart?

I was configuring apache tomcat's context path to be root ('/'), but after doing that, I noticed whenever I started or restarted my server in eclipse, the root's servlet's doGet method would get called.

Here's what I did.

  1. In my web project's setting, I changed the context path to '/'.
  2. I removed the web app from my tomcat server, and redeployed it on it.
  3. I configured a servlet that has a url-mapping to '/', so that I could access localhost:8080/ and my servlet would get called.

I added a "System.out.println("Hello World");" inside the doGet method of that servlet, so I noticed that when I start/restart the tomcat server in elcipse, the servlet's doGet method gets called.

Why does this happen, and is this normal behavior? I would imagine that the servlet's doGet method only gets called when a GET request is made to that servlet, so I don't understand why it's getting called when I start/restart the tomcat server in eclipse.

Tomcat does not do anything. However Eclipse's WTP plugin sends a real request for / on all configured connectors to check if the server is running. If Tomcat answers the server's status in Eclipse changes from starting to started/debugging .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM