Which of following annotations can be used in a servlet class?
@javax.annotation.Resource
@javax.annotation.PreDestroy
@javax.annotation.security.RunAs
@javax.annotation.security.RolesAllowed
@javax.servlet.annotation.WebServlet
A.
(v) only
B.
(i) and (v)
C.
(i), (ii), (iii) and (v)
D.
(i), (ii), (iv) and (v)
E.
(i), (ii), (iii), (iv) and (v)
Explanation:
* (i) The javax.annotation.Resource annotation is used to declare a reference to a
resource. @Resource can decorate a class, a field, or a method.
* (v) javax.servlet.annotation
Annotation Type WebServlet
Annotation used to declare a servlet.
This annotation is processed by the container at deployment time, and the corresponding servlet
made available at the specified URL patterns.
Incorrect:
* Not (II) : javax.annotation.PreDestroy
Target: Method
C
C
C is wrong because the @PreDestroy target is Method, not Type, so it can’t be applyed to the class implementing the servlet. The only possible option is B
Agree with giuseppe
As we can see at comments after ask