简体   繁体   English

我想在jetty中同时使用@WebServlet注释和@Path注释

[英]I want to using @WebServlet annotation and @Path annotation to same time in jetty

First, Please forgive me for my clumsy English. 首先,请原谅我笨拙的英语。

[What I want to do] [我想做的事]

I want to know @WebServlet annotation by Servlet 3.0 and @Path annotation by Jersey 2.22.2, It is able to using same time? 我想知道Servlet 3.0的@WebServlet注释和Jersey 2.22.2的@Path注释,它能够同时使用吗?

[That I want is to help] [我想要的是帮助]

  • Can I use two annotations at the same time? 我可以同时使用两个注释吗?
  • If I can use those annotations, is that way how to use? 如果我可以使用那些注释,那是怎么用的?

Thank you. 谢谢。

@Path annotation defines a path to a RESTful Web service so when you have @Path("/SomeService") it will translate into www.yourapp.com/baseRestUrl/SomeService. @Path注释定义了RESTful Web服务的路径,因此当您拥有@Path(“/ SomeService”)时 ,它将转换为www.yourapp.com/baseRestUrl/SomeService。 You can also define it on the methods which provides REST services. 您还可以在提供REST服务的方法上定义它。 Note that baseRestUrl is defined inside web.xml or in class which extends Application class. 请注意,baseRestUrl是在web.xml或扩展Application类的类中定义的。

On the other hand @WebServlet("/SomePath") states that Servlet will be listening for request on the www.yourapp.com/SomePath, it is basically replacement of servlet-mapping element in web.xml. 另一方面, @ WebServlet(“/ SomePath”)声明Servlet将在www.yourapp.com/SomePath上侦听请求,它基本上是替换web.xml中的servlet-mapping元素。 You can still configure servlets like this, it's up to you whether you prefer XML or annotation configuration. 您仍然可以像这样配置servlet,无论您喜欢XML还是注释配置,都取决于您。

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

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