Jsp programming @ WebServlet details, jsp @ webservlet details
After compiling the Servlet, I will tell the Web Container some information about the Servlet. In Servlet 3.0, you can use Annotation to tell the container which servlets will provide services and additional information. For example, in HelloServlet. java:
@ WebServlet ("/hello. view") public class HelloServlet extends HttpServlet {as long as @ WebServlet annotation is set on the Servlet, the container will automatically read the information in it. The above @ WebServlet tells the container that if the request URL is "/hello. view", the HelloServlet instance will provide services. You can use @ WebServlet to provide more information. @ WebServlet (name = "Hello", urlPatterns = {"/hello. view"}, loadOnStartup = 1) public class HelloServlet extends HttpServlet {
The above @ WebServlet informs the container that the Servlet HelloServlet name is Hello, which is specified by the name attribute, and if the client request URL is/hello. view is processed by the Servlet with the Hello name, which is specified by the urlPatterns attribute. When using annotation in Java EE-related applications, you can remember that the default value is usually used for unspecified properties. For example, if the name attribute of @ WebServlet is not set, the default value is the complete name of the Servlet class.
When the application is started, no Servlet instances are actually created. When the container first requests a Servlet service, the corresponding Servlet class is instantiated, initialized, and then processed. This means that the client requesting the Servlet for the first time must wait for the time required to instantiate the Servlet class and perform the initial action to get the request processing.
If you want to load, instantiate, and initialize the Servlet class when the application starts, you can use loadOnStartup. Set a value greater than 0 (default value:-1), indicating that the Servlet will be initialized after the application is started (instead of instantiating several servlets ). The number indicates the initial sequence of the Servlet. The container must first initialize the Servlet with a small number, if multiple servlets use the same number when setting loadOnStartup, the container vendor can decide which Servlet to load.
Thank you for reading this article. I hope it will help you. Thank you for your support for this site!