Issue
I have inherited a large project that I am trying to better understand.
I have seen classes that act as servlets but that don't extend HttpServlet
or implement any interfaces. Yet their methods are mapped to URIs.
How does this magic happen? Could it be something to do with Spring? web.xml
? pom.xml
?
Sorry if the question is too vague. I've been reading a number of tutorials on servlets, and they all seem to indicate the class must extend HttpServlet
or similar. I'm at a loss as to how they work without that, so it is difficult to ask a more specific question.
Solution
It could be Java Enterprise Edition http://docs.oracle.com/javaee/7/tutorial/doc/home.htm
If the class has a @Path annotation, it could be a RESTful web service. Something like this:
@Path("helloworld")
public class HelloWorld {
GET
@Produces("text/html")
public String getHtml() {
return "<html lang=\"en\"><body><h1>Hello, World!!</h1></body></html>";
}
Modern Java EE Containers provide lots of functionality through very economical annotations.
Edit: The relevant part of the Oracle Java EE 7 tutorial is http://docs.oracle.com/javaee/7/tutorial/doc/jaxrs002.htm#GILIK
Answered By - user384842