Jsp programming @ WebServlet details, jsp @ webservlet details

Source: Internet
Author: User

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.