File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes why are there 2 elements for urlpatterns in WebServlet annotation type ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "why are there 2 elements for urlpatterns in WebServlet annotation type ?" Watch "why are there 2 elements for urlpatterns in WebServlet annotation type ?" New topic
Author

why are there 2 elements for urlpatterns in WebServlet annotation type ?

gurpeet singh
Ranch Hand

Joined: Apr 04, 2012
Posts: 924
    
    1

the jee 6 api for WebServlet annotation type has two elements value and urlPatterns both for defining the url patterns for the servlet. why are there 2 elements for the same thing ?
gurpeet singh
Ranch Hand

Joined: Apr 04, 2012
Posts: 924
    
    1

yeah i got the answer to this one after reading the servlet 3.0 specifications. there are 2 elements in the @WebServlet annotation viz value and urlPatterns. the specifications says that if you are using single element then you should use value element and when you are using it with other attributs you should use urlPatterns. i think value element is there to specify the annotation in shortcut way. consider following example :

@WebServlet(urlPatterns={"/foo","/bar"},name="MyServlet") // using urlPatterns element

@WebServlet(/foo) // you need not specify value="/foo" ;you can use the shortcut and directly right the value(withouth = sign) when there is only a single element with the name value.

Regards
gurpreet
 
 
subject: why are there 2 elements for urlpatterns in WebServlet annotation type ?