I am new to using Java Servlets. From what I've seen so far, there are a number of ways to do the initial routing of a url, such as using @WebServlet
url patterns as well as using web.xml.
From the way I see it, web.xml is really the router. Alternatively, I could wildcard all routes to single servlet, use that as a front router to some extent and do pattern matching in Java with something like request.getPathInfo();
, then call other servlets from that. The implication would be that each servlet that gets called is a new thread, right?
My question is, what are the implications of doing this, such as the fact that if this is done, doesn't this mean that the servlet is restarted and reinitialized every single time? Is this the way servlets are designed to be used? Is it an okay idea to route all requests to one servlet and then use the servlet as a router?