aspose 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


Win a copy of Java 8 in Action this week in the Java 8 forum!
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: 923
    
    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 ?


OCPJP 6(100 %) OCEWCD 6(91 %) OCPJBCD(93%)
gurpeet singh
Ranch Hand

Joined: Apr 04, 2012
Posts: 923
    
    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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: why are there 2 elements for urlpatterns in WebServlet annotation type ?
 
Similar Threads
Servlets access directly.
Can we make a web application without using web.xml
Difference between value and urlPatterns attribute in WebServlet annotation
web.xml vs annotations
@WebServlet annotation is not working