Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Unregistered Servlets?  RSS feed

 
Amit Saksena
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the description for the method ServletConfig#getServletName(), it states that the servlet name may be provided via server administration, assigned in the web application deployment descriptor, or for an unregistered (and thus unnamed) servlet instance it will be the servlet's class name.

What is an unregistered servlet?
How exactly would the DD entry for such a servlet look like, if any?
What would be the request url for such a servlet, in the client code (action="" or href="")?
 
Ivan Jozsef Balazs
Rancher
Posts: 999
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Servlets can be annotated instead of (or besides) web.xml description.
Look up "package javax.servlet.annotation" and the J2EE documentation.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66143
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that annotations are only available in Servlets 3.
 
Amit Saksena
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, @WebServlet would do the servlet declaration analogous to the one in web.xml. So if I just define the url mapping for the servlet, say @WebServlet("/*"), the getServletName() method prints the fully qualified class name of the Servlet class, as there is no servlet name specified in the annotation.
The docs that I'm referring are for JavaEE 5, and there weren't any annotations in the specification. And I don't understand how is it bound to a specific version of JEE.
Also, my question is not related to the functionality of getServletName() method. It's rarely used. Am just curious, what unregistered servlets are, how would they be declared and how & when should they be used?
It has been explained to an extent in the following discussion, but I couldn't really make things work at the code level.

http://www.coderanch.com/t/347020/Servlets/java/difference-registered-unregistered-servlets
 
Ivan Jozsef Balazs
Rancher
Posts: 999
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It has been explained to an extent in the following discussion


The question boils down partially to what "unregistered servlet" actually means.

Well, that discussion dates back to 2000.

Servlets were invented before Java 1.5, which introduced annotations to Java.

So in 2000 the expression "unregistered servlet" could simply not refer to "servlet not described in web.xml but by the annotations introduced with Servlet API v3.0".
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!