Skip to main content

annotations in JSP 2.1 specification

1 reply [Last post]
toshe
Offline
Joined: 2005-03-22
Points: 0

Hi experts,

I have read the JSP 2.1, Servlet 2.5 and JavaEE 5 specifications. However nothing is explicitely specified about annotations in JSP and tag files. The only assumption which can be made is that as JSP files extend javax.servlet.Servlet so they could be annotated. Looking at table J2EE.5-1 “Components classes supporting injection” only tag handlers and tag library event listeners are specified. As event listeners are both mentioned in JSP and Servlet rows of the table, why JSP pages are not specified in the JSP row? Should it be able to annotate JSP page?

The other relevant question is if the event listeners described in the web.xml support all 7 annotations described in Servlet 2.5 specification why the other event listeners described in TLD should support only @Resource, @EJB, @WebServicesRef?

And finally why JSP 2.1 specification limits usage of @InjectionComplete annotation? Why tags, event listeners (and JSP pages) cannot define a method and annotate it with @InjectionComplete?

Thanks,
Todor

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jluehe
Offline
Joined: 2004-12-01
Points: 0

Hi Todor,

the reason that annotations are not supported on JSP pages or tag files is because all the information represented by annotations needs to be known at deployment time. If an annotation is included in a JSP page, it won't be seen at deployment time (unless the JSP was being precompiled during deployment).

TLD listeners support the exact same annotations as Servlet event listeners. JSP.7.1.11 is going to reflect this and is going to list the following supported annotations:

@Resource + @Resources
@EJB + @EJBs
@WebServiceRef
@PostConstruct
@PreDestroy
@PersistenceContext + @PersistenceContexts
@PersistenceUnit + @PersistenceUnits

Notice that @InjectionComplete has been replaced by @PostConstruct and @PreDestroy listed above.

Let me know if you have any further questions.

Jan