简体   繁体   English

不扩展Servlet类的Java Servlet

[英]Java Servlets Without Extending a Servlet Class

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. 我见过充当servlet的类,但是它们没有扩展HttpServlet或实现任何接口。 Yet their methods are mapped to URIs. 但是,它们的方法已映射到URI。

How does this magic happen? 这种魔术是如何发生的? Could it be something to do with Spring? 可能与Spring有关吗? web.xml ? web.xml pom.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. 我已经阅读了许多关于servlet的教程,它们似乎都表明该类必须扩展HttpServlet或类似的东西。 I'm at a loss as to how they work without that, so it is difficult to ask a more specific question. 如果不这样做,我将无所适从,因此很难提出更具体的问题。

It could be Java Enterprise Edition http://docs.oracle.com/javaee/7/tutorial/doc/home.htm 它可能是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. 如果该类具有@Path批注,则它可能是RESTful Web服务。 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. 现代的Java EE容器通过非常经济的注释提供了许多功能。

Edit: The relevant part of the Oracle Java EE 7 tutorial is http://docs.oracle.com/javaee/7/tutorial/doc/jaxrs002.htm#GILIK 编辑:Oracle Java EE 7教程的相关部分是http://docs.oracle.com/javaee/7/tutorial/doc/jaxrs002.htm#GILIK

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM