Adding Web Annotation Tags

Annotation-based programming tags are used within your web projects as providers of metadata that is then used to generate other application artifacts as required. You add these tags to your code in the same way that you add Javadoc comments.

Annotation-based programming tags form part of an Dynamic Web Project..
  1. Adding class-level annotations can be done using the New Dynamic Web Project wizard. On the New Dynamic Web Project page, click the Show Advanced >> push button. Select the Add support for annotated Java classes check box.



  2. You can automatically generate an annotated servlet class using the Create Servlet wizard. Select the Generate an annotated servlet class check box, and it will create a default annotated servlet class for you. The code for the annotated servlet class is as follows:



This default annotated servlet class illustrates the three basic parts of annotation-based programming:
  • The first element is the phrase
    * Servlet implementation class for Servlet: MyServlet

    This phrase represents the source code comment explaining the function / purpose of this class.

  • The second element includes the asterisk and @ symbol::
    * @

    The @ sign indicates that what follows is an annotation that needs to be processed.

  • The third element is the body of the annotation tag:
     * @web.servlet
     *   name="myServlet"
     *   display-name="myServlet" 
     *
     * @web.servlet-mapping
     *   url-pattern="/myServlet"
     *  

    This code contains the annotations that will be used to generate the artifacts. In this case, the annotation specifies that it is of the web.servlet type, which defines data relating to servlets. The tag also specifies values for the parameters name, display-name, and url-pattern.

The artifacts specified by the annotation tags will be generated at run time.

Related Reference

Terms of use | Feedback
(C) Copyright IBM Corporation 2000, 2005. All Rights Reserved.